2013-07-25 59 views
0

是否可以在折線圖中禁用LineSeries組件的特定圖例。禁用折線圖中的特定圖例

讓我們說,我們有下面的代碼:

<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}"/> 

這將產生如下線圖:

enter image description here

而這樣的結果,我想:

enter image description here

UPDATE:

裸記住,我必須使用傳說的dataProvider爲myChart因爲數據是動態生成。此外,圖例是自定義的。而不是使用您的圖表作爲dataProvider,

回答

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]; 
} 
0

,您可以創建個人LegendItems

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

EDIT2:試試這個

<mx:Legend dataProvider="{new ArrayCollection(myChart.legendData).getItemAt(0)}"> 
+0

感謝您的幫助,但我只是想使用DataProvider作爲數據動態構建的圖例 – kaissun

+1

請參閱編輯。你能否更具體地瞭解這些數據:傳說是否改變了? –

+0

首先,第二種解決方案不起作用:legendItems對象總是空的,因爲我動態設置數據。關於數據,我從XML文件中讀取數據。這就是爲什麼我不知道線路系列,只是我有一個屬性,我可以使用它不顯示圖例。 是否有任何屬性可能與線系列組件本身有關? – kaissun