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

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

问题描述

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

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!

推荐答案

我详细阐述了 Luis B 的回答,以使其动态反映在折线图的数据提供者上.这样,图例仅显示图表中可用的字段.有点俏皮.

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

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

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.

请随意为这个答案点赞,FLEX FOLKS!

FEEL FREE TO UPVOTE THIS ANSWER, FLEX FOLKS!!

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

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