Search code examples
apache-flexflex-mx

Flex Chart, determining chart area (not including


I am working on a flex application comparing multiple instance of the mx:PlotChart class. I need normalize the various instances of the PlotCharts such that the change in data value per pixel between charts remains constant. To do this, I must find the area of the chart actually used for graphing (and not for the axis labels). The area I am looking for is show (highlighted in fuschia) in the attached screen shot.

Thanks, -Kevinenter image description here


Solution

  • I think you're looking for the width and height of the series. Below is an example using a ColumnChart, but of course this will work for another type of chart such as LineChart.

    Suppose we have the following data:

    <mx:XMLListCollection id="dp">
    <fx:XMLList>
        <quote date="8/1/2007" open="40.29" close="39.58" />
        <quote date="8/2/2007" open="39.4" close="39.52" />
        <quote date="8/3/2007" open="39.47" close="38.75" />
        <quote date="8/6/2007" open="38.71" close="39.38" />
        <quote date="8/7/2007" open="39.08" close="39.42" />
        <quote date="8/8/2007" open="39.61" close="40.23" />
        <quote date="8/9/2007" open="39.9" close="40.75" />
        <quote date="8/10/2007" open="41.3" close="41.06" />
        <quote date="8/13/2007" open="41" close="40.83" />
        <quote date="8/14/2007" open="41.01" close="40.41" />
        <quote date="8/15/2007" open="40.22" close="40.18" />
        <quote date="8/16/2007" open="39.83" close="39.96" />
        <quote date="8/17/2007" open="40.18" close="40.32" />
        <quote date="8/20/2007" open="40.55" close="40.74" />
        <quote date="8/21/2007" open="40.41" close="40.13" />
        <quote date="8/22/2007" open="40.4" close="40.77" />
        <quote date="8/23/2007" open="40.82" close="40.6" />
        <quote date="8/24/2007" open="40.5" close="40.41" />
        <quote date="8/27/2007" open="40.38" close="40.81" />
    </fx:XMLList>
    </mx:XMLListCollection>
    

    And the following chart:

    <mx:ColumnChart id="myChart" dataProvider="{dp}" showDataTips="true" width="300">
    <mx:horizontalAxis>
        <mx:CategoryAxis categoryField="@date"/>
    </mx:horizontalAxis>
    <mx:series>
        <mx:ColumnSeries id="openSeries"
            xField="@date" 
            yField="@open" 
            displayName="Open"/>
    </mx:series>
    </mx:ColumnChart>
    

    Then we can access the width and height of the series:

    <s:Label text="{openSeries.width}" />
    <s:Label text="{openSeries.height}" />