Pre loader

Include/Exclude a series in the Legend in SciChart.js

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Greetings,
i have three Series in a SciChart.js (Community-Version) Surface.
The Legend i added shows me all three of them and their names and checkboxes do hide or show the series.

Here is my problem: Is there a way to hide one Series (a FastCandlestickRenderableSeries) from the Legend? I only want to show the other two Series (FastLinerenderableSeries).

Somethin like a Parameter “showInLegend: false,”? I did not find something like this in the documentation(https://www.scichart.com/documentation/js/current/typedoc/classes/legendmodifier.html).

Thank you

Version
3.2.446
  • You must to post comments
1
0

Wow, this helped a lot. Thank you.

Unfortunately the code did not work out of the box. After fiddling a little around with the implementation and error-Message, i found out, that the sequence of codelines need to be modified.

const renderableSeries0 = sciChartSurface.renderableSeries.get(0);
const renderableSeries1 = sciChartSurface.renderableSeries.get(1);
const legendModifier = new LegendModifier();
sciChartSurface.chartModifiers.add(legendModifier); // required or below crashes
legendModifier.includeSeries(renderableSeries0, false); // excludes a series
legendModifier.includeSeries(renderableSeries1, true); // includes a series

i needed to add the Modifier to the Surface before i include or exclude any series.
When i tried to add the Modifier after i excluded/included Series, i received the error message:
Uncaught (in promise) TypeError: this.parentSurface is undefined

  • You must to post comments
1
0

Hi Sebastian,

As part of our ongoing work to create the best developer experience I’m actually going through all these documentation pages and updating them with embedded codepens. The Legend, Cursor, Rollover are on my todo list next!

So there is a way to include/exclude a specific series from the legend. What you want to do is use legendModifier.includeSeries. By default all series are included and must be excluded individually.

const renderableSeries0 = sciChartSurface.renderableSeries.get(0);
const renderableSeries1 = sciChartSurface.renderableSeries.get(1);

const legendModifier = new LegendModifier();
legendModifier.includeSeries(renderableSeries0, false); // excludes a series
legendModifier.includeSeries(renderableSeries1, true); // includes a series

You can inspect which series are included or excluded at any time via the LegendModifier.includedSeriesMap. Note I do not recommend modifying this collection but use the functions above instead.

Finally, the CursorModifier, RolloverModifier and several other zooming panning modifiers all have similar functions to includeSeries or includeAxis.

Let me know if this helps

Best regards
Andrew

  • You must to post comments
0
0

Wow, this helped a lot. Thank you.

Unfortunately the code did not work out of the box. After fiddling a little around with the implementation and error-Message, i found out, that the sequence of codelines need to be modified.

const renderableSeries0 = sciChartSurface.renderableSeries.get(0);

const renderableSeries1 = sciChartSurface.renderableSeries.get(1);

const legendModifier = new LegendModifier();

sciChartSurface.chartModifiers.add(legendModifier);

legendModifier.includeSeries(renderableSeries0, false); // excludes a series

legendModifier.includeSeries(renderableSeries1, true); // includes a series

i needed to add the Modifier to the Surface before i include or exclude any series.
When i tried to add the Modifier after i excluded/included Series, i received the error message:

Uncaught (in promise) TypeError: this.parentSurface is undefined

  • You must to post comments
0
0

Yes of course, sorry,

I assumed the LegendModifier was already on the chart surface. That error though should be handled.

FYI you can fetch modifiers from the surface using const legend = sciChartSurface.chartModifiers.asArray().find(m => m.type === EChart2DModifierType.Legend).

This will save you having to pass legend around when creating new series and adding to the chart.

Also check out the TypeDoc if you haven’t found it already! Available at the bottom of the Treeview on the main docs. A list of all the properties available and their types can be found, e.g. LegendModifier.type is here.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.