如何排除图例系列(Flex)

Sea*_*hen 5 apache-flex legend

在弹性图表中,我想画一些与特定系列相关的"参考线",因此这些线不是独立的系列,不应该在图例中显示.是否可以从图表图例中排除某些系列?谢谢!

D3v*_*r0n 10

我详细阐述了Luis B的答案,使其能够动态反映在线图的数据提供者身上.这样,图例仅显示图表中可用的字段.有点漂亮.

这是我提出的,它运作良好:

        protected function onUpdateLinechartComplete(e:FlexEvent):void 
        {

            //empty legend for fresh display
            var legendArray:Array = new Array();
            legend1.dataProvider = legendArray;

            //filter Legend data so that only LineSeries with data can be shown
            for(var i:int=0; i< linechart1.legendData.length; i++) {

                //if data is found in the line series, let's add it to the chart legend data provider, so it can be displayed in the legend
                if (linechart1.legendData[i].element.items.length != 0) {
                    legendArray.push(linechart1.legendData[i]); 
                }

            }
            legend1.dataProvider = legendArray;
            legend1.direction = "vertical";
        }



//in the page Initialize function, I add a listener event to the linechart component for when the legend update completes so it can filter lineseries on the legend's dataprovider in [onUpdateLegendComplete]
linechart1.addEventListener(FlexEvent.UPDATE_COMPLETE, onUpdateLinechartComplete);
Run Code Online (Sandbox Code Playgroud)

我最终不得不使用EventHandler并将事件监听器附加到线图本身.这是因为我遇到了传奇数据提供者的"竞争条件".有些东西可以使用,有时它不会.使用事件Listener消除了该问题,并仅在线图完成加载数据时过滤图例.

免费提供这个答案,FLEX FOLKS !!


Lui*_*s B 7

可以从图表图例中排除某些系列.

每个图表类(扩展ChartBase)都有一个legendData Array属性.这个legendData有一个LegendItem列表.如果你创建一个基于legendData的newArray,但只有你想要的LegendItem; 然后,您可以将该数组设置为图例的dataProvider.

此外,您可以基于从头创建的LegendItems创建自己的LegendItem数组.并使用该数组作为Legend的dataProvider.

例如,这里我只显示我的图例中的第一个和第三个系列:

<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)" />
Run Code Online (Sandbox Code Playgroud)

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