Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude series in legend (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!

like image 973
Sean Chen Avatar asked Mar 22 '10 10:03

Sean Chen


People also ask

How do I remove this series from the legend only?

How do I remove this series from the legend only? Thanks. click on the legend, then click again on the item in the legend that you want to delete (click on the text portion of the item)..you should get the six little black squares surrounding just that item....now you can press delete on your keyboard. Where there is a will there are many ways.

How do you exclude items from a legend in Python?

To exclude items from a legend, you can specify the objects that you want to include as the first input argument to the “legend” function. For example, plot three lines and return the “Line” objects as array “p”. Include only the first and third lines in the legend by specifying “p (1)” and “p (3)” as the first input argument to “legend”.

How to delete a legend in Excel 2016?

In Excel 2016 it is same, but you need to click twice. - Then click on the specific legend which you want to remove. - And then press DELETE. If my reply answers your question then please mark as "Answer", it would help others to find their solution easily from your experience.

How do I leave an item out of a legend?

Sign in to answer this question. Starting in R2021a, you can leave an item out of a legend by setting the corresponding label to an empty character vector. For example, plot three lines. Then call the legend function and specify the second legend label as an empty character vector.


Video Answer


1 Answers

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!!

like image 189
D3vtr0n Avatar answered Sep 30 '22 14:09

D3vtr0n