Pre loader

What is the best way to Color code individual data points in a 2D Chart?


Hi SciCharters,
I would like to create a color coded 2D scatter plot.
My approach is the IPointMarkerPaletteProvider interface. It works, but I have experienced a huge performance difference when I individually colored every datapoint of my 2D chart and using a static color.
When I use the same provider but only a single color there is no performance issue at all.

Here is the relevant code of my PointMarkerPaletteProvider interface:

 public PointPaletteInfo? OverridePointMarker(IRenderableSeries rSeries, int index, IPointMetadata metadata)
            var myMetaData= metadata as MyRecordMetadata;
            var colorBarPosition = GetColorBarPosition(myMetaData.PlotValue);

            _pointMarkerColorOverrides.Fill = _ColorBar[colorMapPosition];
            _pointMarkerColorOverrides.Stroke = _ColorBar[colorMapPosition];
             return _pointMarkerColorOverrides;

The _ColorBar contains only 256 values and the Color is selected according to the myMetaData.PlotValue in GetColorBarPosition().
The series is plotted as expected, but it takes “ages”(seconds for 4000 data points) for rendering it on the chart.
If I replace the assignments of _pointMarkerColorOverrides.Stroke and _pointMarkerColorOverrides.Fill with one static color, there’s no performance issue at all.

I was just curious if that is the expected behaviour? Would it be better (in terms of performance) to switch to another chart type (e.g. heatmap chart) to plot color coded values?

  • You must to post comments

At first glance, I would think that your reuse of a local instance of the PointPaletteInfo object (_pointMarkerColorOverrides) might be causing this issue. The first point goes great, but then the next one changes the property underneath, and the first one tries to update bindings. Then, the third one causes the first and second to update… see where I am going?

Try just returning a new instance each time (warning, fully untested code ahead – treat like pseudo-code :+) :

return new PointPaletteInfo { Fill = _ColorBar[colorMapPosition], Stroke = _ColorBar[colorMapPosition] };

I may be way off base here, but I am using a heatmap palette provider (in the 5.0 beta), and I return new Color structures on every call, and can render 1000×1000 datapoints real snappy like…

Just a thought.

  • Tim
    Hi Mike, thanks for the hint. I tried that, but unfortunately it did not change the performance. I even went a step further and removed any additional code (GetColorBarPosition) in the palette provider and set the color earlier in a metadata property. Again this didn’t improve the performance. I played around with the number of colors and this made a huge difference. I’ve got to admit that 256 colors is quite a lot and a bit oversized. But even with 16 colors the zoom and pan is a bit choppy. Anyway, thanks again for your help. I might try one of the 3D charts, to see if there’s any difference. Otherwise, I use a limited number of colors..
  • Andrew Burnett-Thompson
    Hey guys, there’s a known performance issue in Scatter series when using PaletteProvider. It’s a case of when the pens are changed we flush the graphics pipeline and create a new sprite for the renderer. Not ideal. What we need is a XyColorScatterSeries which accepts data in Xyz format (where z = integer color). If we could do it all in one drawing pass it will fly. It takes a bit of work though …. I will bump the priority and ask the team to look into it.
  • You must to post comments
Showing 1 result
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