0

Is there any possibility to disable a particular legend for LineSeries component in a line chart.

Let say that we have the following code:

<mx:Panel title="Line Chart">
 <mx:LineChart id="myChart" 
    dataProvider="{expenses}" 
    showDataTips="true"
 >
    <mx:horizontalAxis>
       <mx:CategoryAxis 
            dataProvider="{expenses}" 
            categoryField="Month"
        />
    </mx:horizontalAxis>
    <mx:series>
       <mx:LineSeries 
            yField="Profit" 
            displayName="Profit"
       />
       <mx:LineSeries 
            yField="Expenses" 
            displayName="Expenses"
       />
    </mx:series>
 </mx:LineChart>
 <mx:Legend id="legend" dataProvider="{myChart}"/>

It will produce the following line chart:

enter image description here

And this the result that i want:

enter image description here

UPDATE:

Bare in mind that I have to use the legend's DataProvider as myChart because the data is dynamically build. Also, the legend is customized.

4

3 回答 3

0

得到了解决方案,因为我有自定义图例,我必须在更新折线图后设置数据提供者图例:

 // Add listener event to the linechart component for when the legend update completes so it can filter lineseries on the legend's dataprovider in [onUpdateLegendComplete]
    myChart.addEventListener(FlexEvent.UPDATE_COMPLETE, onUpdateLinechartComplete);

功能是:

protected function onUpdateLinechartComplete(e:FlexEvent):void 
{
    legend.dataProvider = myChart.legendData[0];
}
于 2013-07-30T10:57:35.620 回答
0

结帐http://flexdevtips.blogspot.com/2009/10/linechart-with-checkbox-legend.html它可能会给你一些想法。

于 2013-10-14T16:38:29.390 回答
0

而不是使用您的图表作为 DataProvider,您可以创建单独的 LegendItems

    <mx:Legend>
        <mx:LegendItem label="Profit" fill="#e48701">           
        </mx:LegendItem>
    </mx:Legend>

编辑2:试试这个

    <mx:Legend dataProvider="{new ArrayCollection(myChart.legendData).getItemAt(0)}">
于 2013-07-25T09:29:19.283 回答