如何排除图例中的系列(Flex) [英] How to exclude series in legend (Flex)

查看:178
本文介绍了如何排除图例中的系列(Flex)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在flex charting中,
我想绘制与特定系列相关的参考线,
,因此这些线不是独立的系列,不应该显示在图例中。
是否可以从图表图例中排除一​​些系列?
Thanks!

解决方案

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



这是我想到的,它运作良好:

  {
$ b $ //新鲜显示的空图例
var legendArray:Array = new Array();
legend1.dataProvider = legendArray;

//过滤图例数据以便只显示包含数据的LineSeries
for(var i:int = 0; i< linechart1.legendData.length; i ++){

//如果在系列中找到数据,我们将它添加到图表图例数据提供程序中,以便它可以显示在图例
中(如果(linechart1.legendData [i] .element.items)。 length!= 0){
legendArray.push(linechart1.legendData [i]);
}

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



$ b //在页面中初始化函数,我添加一个监听器事件到图表组件,当图例更新完成时,它可以过滤线条系列[onUpdateLegendComplete]中的图例数据提供者
linechart1.addEventListener(FlexEvent.UPDATE_COMPLETE,onUpdateLinechartComplete);

我最后不得不使用EventHandler并将事件监听器附加到线图本身。这是因为我遇到了传奇数据提供商的竞争条件。有些时候它会起作用,有时候不会。使用Listener事件消除了这个问题,并且只在线图完成加载数据时过滤图例。



免费升级本答案, p>

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!

解决方案

I elaborated on Luis B's answer to make this dynamically reflect on the linechart's data provider. This way the legend only shows what fields are available in the chart. Kinda nifty.

Here is what I came up with, and it works well:

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

I ended up having to use an EventHandler and attaching an event Listener to the linechart itself. This is because I was experiencing "race conditions" with the legend's data provider. Sometmes it would work, sometimes it would not. Using the event Listener eliminated that problem, and only filters the legend when the linechart has completed loading it's data.

FEEL FREE TO UPVOTE THIS ANSWER, FLEX FOLKS!!

这篇关于如何排除图例中的系列(Flex)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆