Pre loader

How to hide a series from the LegendModifier

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

I have a bunch of series (XyScatterSeries) that I am using to draw different markers (triangle, circle, cross) based on the data. I also have couple line series too in the chart.

The line series should be displayed in the LegendModifier, but not any of the scatter series.

I tried setting “includeSeries” function here but that didn’t work (typescript kept complaining about it but I kept it and while running the app it didn’t hide the series):

return new LegendModifier({
        showCheckboxes: true,
        orientation: ELegendOrientation.Vertical,
        placement: ELegendPlacement.TopRight,
        includeSeries: (series: IRenderableSeries, isIncluded: boolean): void => { return false; },
    });

Then I created my own class “MyLegendModifier” deriving from LegendModifier, but that didn’t do anything either.

class MyLegendModifier extends LegendModifier {
    constructor(options?: ILegendModifierOptions) {
        super(options);
    }

    includeSeries(series: IRenderableSeries, isIncluded: boolean) {
        console.log('includeSeries:', series.id);
        if (series.id.startsWith('BUY:') || series.id.startsWith('SELL:')) {
            isIncluded = false;
        }
        super.includeSeries(series, isIncluded);
    }
}

Any advise please.

Version
2.2.2397
  • You must to post comments
1
0

Never mind – I fixed it by overriding the “getIncludedRenderableSeries” method instead as shown below.

class MyLegendModifier extends LegendModifier {
    constructor(options?: ILegendModifierOptions) {
    super(options);
}

override getIncludedRenderableSeries(): IRenderableSeries[] {
    return super.getAllSeries().filter((value) => !value.id.startsWith('BUY:') && !value.id.startsWith('SELL:'));
}

}

  • Andrew Burnett-Thompson
    Hi Sachin, great you fixed it! I think includeSeries is intended to be used differently than that. I’ll look it up as we should support this out of the box. A+ for overriding and finding a workaround!
  • You must to post comments
0
0

Hi Sachin,

Thanks for sharing your solution, that’s great that you found a workaround! Do keep it on the forum as these kind of tips can help other users navigate the library.

Another idea for you, LegendModifier.includeSeries() supports this functionality. It can’t be set from constructor options of the modifier.

This is how it works

const lineSeriesA = new FastLineRenderableSeries(wasmContext);
const lineSeriesB = new FastLineRenderableSeries(wasmContext);

const legend = new LegendModifier();
legend.includeSeries(lineSeriesB, false); // By default this flag is true, set to false just for lineSeriesB

sciChartSurface.renderableSeries.add(lineSeriesA);
sciChartSurface.renderableSeries.add(lineSeriesB);

sciChartSurface.chartModifiers.add(legend);

Best regards,
Andrew

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies