This is a migrated thread and some comments may be shown as answers.

Is it possible to hide the legend for a series?

1 Answer 401 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 13 Dec 2013, 12:43 PM
So I have a graph with multiple series.

.Series(series => {
     series.Line(model => model.SentFiles).Name("Sent");
     series.Line(model => model.ReceivedFiles).Name("Received");
     series.Column(model => model.SentFiles).Name("Sent Data");
     series.Column(model => model.ReceivedFiles).Name("Received Data");
     series.Area(model => model.ReceivedFiles).Name("Received Data").Labels(false);
     series.Area(model => model.SentFiles).Name("Sent Data").Labels(false);
})

because I want my users to be able to show and hide multiple different types of data in 1 graph

I have worked out how to hide series

for (var i = 0, length = series.length; i < length; i++) {
     series[i].stack = stack;
     series[i].visible = (types.indexOf(series[i].type) != -1);
};

however the legend for the series just "grays out".

I want to be able to show and hide the legend as I show and hide the series.

can you please advise how I can achieve this.

Thanks

*** EDIT  ***

Ok so my initial problem was hiding the legends dynamically, this has been solved.
However, I now have the issue of setting the initial setup of the series and legends...

So I can do the following

.Series(series =>
{
     series.Line(model => model.SentFiles).Name("Sent");
     series.Line(model => model.ReceivedFiles).Name("Received");
     series.Column(model => model.SentFiles).Name("Sent Data").Visible(false);
     series.Column(model => model.ReceivedFiles).Name("Received Data").Visible(false);
     series.Area(model => model.ReceivedFiles).Name("Received Data").Visible(false);
     series.Area(model => model.SentFiles).Name("Sent Data").Visible(false);
})

which will hide the series, but the legends for those are viewable ("grayed out"). I want a way to initially hide the legends.

I would prefer not having to call a js method on Document.Ready to then hide series

I would have thought if this functionality is available through the JS api that this should be a configurable setting.

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Luke
Top achievements
Rank 1
answered on 13 Dec 2013, 12:49 PM
for anyone else that wants to know you just use the series property "visibleInLegend" to enable or disable the legend visibility

for (var i = 0, length = series.length; i < length; i++) {
    series[i].stack = stack;
     series[i].visible = (types.indexOf(series[i].type) != -1);
     series[i].visibleInLegend = false;
};
Tags
Charts
Asked by
Luke
Top achievements
Rank 1
Answers by
Luke
Top achievements
Rank 1
Share this question
or