tags:

views:

602

answers:

1

Hello, In flex charting, I want to draw something like "reference lines" which are related to specific series, therefore these lines are not independent series and should not be shown in legend. Is it possible to exclude some series from chart legend? Thanks!

+2  A: 

It is possible to exclude some series from the chart legend.

Every chart class (extending ChartBase) has a legendData Array property. This legendData has a list of LegendItem's. If you create a newArray based on the legendData, but with only the LegendItem's that you want; then you can set that array as the dataProvider for your legend.

Also, you can create your own array of LegendItem's based on LegendItems that you create from scratch. And use that array as the dataProvider for the Legend.

For example, here I only display the first and third series in my legend:

<mx:Script>
    <![CDATA[
        private function cc(event:Event):void
        {
            var newArray:Array = new Array();
            newArray.push(myChart.legendData[0]);
            newArray.push(myChart.legendData[2]);

            myActionScriptLegend.dataProvider = newArray;
        }
    ]]>
</mx:Script>

<mx:ColumnChart id="myChart">
    <mx:series>
        <mx:ColumnSeries id="series0"/>
        <mx:ColumnSeries id="series1"/>
        <mx:ColumnSeries id="series2"/>
    </mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{[myChart.legendData[0],myChart.legendData[2]]}" />
<mx:Legend id="myActionScriptLegend" creationComplete="cc(event)" />

http://livedocs.adobe.com/flex/3/langref/mx/charts/chartClasses/ChartBase.html#legendData
http://livedocs.adobe.com/flex/3/langref/mx/charts/LegendItem.html
http://livedocs.adobe.com/flex/3/html/charts_displayingdata_12.html#330954

Luis B
Thank you! Is it also available in actionscript?
Sean Chen
I provided a second legend (id="myActionScriptLegend"), which does the same thing in ActionScript. Hope that helps.
Luis B
Thanks Luis, it helped me solved the problem which was killing lot of my time
Anoop