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
- Sebastian Affeld asked 9 months ago
- last edited 9 months ago
- You must login to post comments
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
- Sebastian Affeld answered 9 months ago
- last edited 9 months ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 9 months ago
- last edited 9 months ago
- You must login to post comments
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
- Sebastian Affeld answered 9 months ago
- last edited 8 months ago
- You must login to post comments
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.
- Andrew Burnett-Thompson answered 9 months ago
- You must login to post comments
Please login first to submit.