0 Replies Latest reply on Aug 8, 2010 11:29 AM by Alvaroecp

    dataToLocal problem?

    Alvaroecp

      Hi everyone,

       

      I have a horizontal DateTimeAxis with minimum and maximum values defined as

      minimum = new Date("2005/7/7");

      maximum = new Date("2005/7/26");.

       

      The axis is part of a CartesianChart with width = 400. When I executes the next instructions, flex returns pointmax = (x=398, y=279.5)

       

                  var datemax:Date = new Date("2005/7/26");
                  const pointmax:Point = (linechart.series[0] as Series).dataToLocal(datemax.time, 0);
                  Alert.show(pointmax.toString());

       

      I dont understand why pointmax.x is 398? I think the correct must be pointmax.x = 400 (because chart's axis and labels were set to be hidden).Additionally, if you use LineChart instead of CartesianChart the values of pointmax.x is 399 ... why??? An example of this problem (in Flasbuilder4) is below.

       

      Thanks in advance!

      -Alvaro

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx"
                     applicationComplete="application1_applicationCompleteHandler(event)">
        
         <fx:Script>
            <![CDATA[
               import mx.charts.chartClasses.Series;
               import mx.collections.ArrayCollection;
               import mx.controls.Alert;
               import mx.events.FlexEvent;
              
               [Bindable]private var expensesAC:ArrayCollection = new ArrayCollection( [
                  { Month: "2005/7/7", Profit: 2000},
                  { Month: "2005/7/11", Profit: 1000},
                  { Month: "2005/7/15", Profit: 1500},
                  { Month: "2005/7/19", Profit: 1800},
                  { Month: "2005/7/26", Profit: 2400} ]);

       

               protected function button1_clickHandler(event:MouseEvent):void
               {
                  var datemin:Date = new Date("2005/7/7");
                  var datemax:Date = new Date("2005/7/26");
                  const theseries:Series = linechart.series[0] as Series;
                  const pmin:Point = theseries.dataToLocal(datemin.time, 0);
                  const pmax:Point = theseries.dataToLocal(datemax.time, 0);
                  Alert.show(pmin.toString() +" : "+ pmax.toString());
               }

       

               protected function application1_applicationCompleteHandler(event:FlexEvent):void
               {
                  (linechart.horizontalAxis as DateTimeAxis).minimum = new Date("2005/7/7");
                  (linechart.horizontalAxis as DateTimeAxis).maximum = new Date("2005/7/26");
               }
            ]]>
         </fx:Script>
        
         <s:layout>
            <s:HorizontalLayout verticalAlign="middle" horizontalAlign="center"
                                paddingLeft="0" paddingRight="0"
                                paddingTop="0" paddingBottom="0"/>
         </s:layout>
            <s:VGroup width="400" height="342" horizontalAlign="center">
                 
                  <mx:CartesianChart id="linechart" height="280" width="400"
                                showDataTips="true" >
                    
                     <mx:series>
                        <mx:LineSeries xField="Month" yField="Profit" form="curve"
                                       dataProvider="{expensesAC}" />
                     </mx:series>
                    
                     <mx:horizontalAxis>
                        <mx:DateTimeAxis id="haxis" displayLocalTime="true" padding="0" />
                     </mx:horizontalAxis>
                    
                     <mx:verticalAxis>
                        <mx:LinearAxis id="vaxis" />
                     </mx:verticalAxis>
                    
                     <mx:verticalAxisRenderers>
                        <mx:AxisRenderer axis="{vaxis}"
                                         showLabels="false" showLine="false" labelGap="0"
                                         tickPlacement="none"
                                         />
                     </mx:verticalAxisRenderers>
                    
                     <mx:horizontalAxisRenderers>
                        <mx:AxisRenderer axis="{haxis}"
                                         showLabels="false" showLine="false" labelGap="0"/>
                     </mx:horizontalAxisRenderers>
                 
                  </mx:CartesianChart>
                  <s:Button label="Button" click="button1_clickHandler(event)"/>
            </s:VGroup>
      </s:Application>