سؤال

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.

هل كانت مفيدة؟

المحلول 2

Got the solution, as i have custom legend I have to set the data provider legend after updating the line chart:

 // 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);

And the function is:

protected function onUpdateLinechartComplete(e:FlexEvent):void 
{
    legend.dataProvider = myChart.legendData[0];
}

نصائح أخرى

Instead using your chart as DataProvider, you could create individual LegendItems

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

edit2: try this

    <mx:Legend dataProvider="{new ArrayCollection(myChart.legendData).getItemAt(0)}">
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top