What is a PaletteProvider?
PaletteProvider is an API that allows to change series color on a point-to-point basis:
Using PaletteProviders
To enable series coloring with PaletteProvider, you need to create a class which implements either IStrokePaletteProvider, or IFillPaletteProvider, or IPointMarkerPaletteProvider, or all of them. A choice depends on a RenderableSeries type which PaletteProvider is planned for. If it has to paint some area in a color that differs from that of rest of a series, implement IFillPaletteProvider. For painting parts of the series' outline, choose IStrokePaletteProvider. To change the fill of some PointMarkers, use IPointMarkerPaletteProvider.
Every PaletteProvider interface declares the only method which returns an array with colors for every data points. For the convenience, there is also the PaletteProviderBase class, which provides some basic implementation. The update() method is called every time a RenderableSeries requires a redraw, so it is supposed that the colors array should be updated there correspondingly.
The following code snippet demonstrates how to create a custom PaletteProvider for a Scatter Series:
Once a PaletteProvider class is ready, its instances can be used to set up the PaletteProvider for a RenderableSeries via the setPaletteProvider() method:
The code above results in a chart with a Scatter Series which change colors of its PointMarkers depending on the threshold levels provided by two HorizontalLineAnnotations:
More examples of PaletteProvider usage can be found in the SciChart Android Examples Suite.
Using PaletteProviders with Heatmaps
There is a special PaletteProvider interface called IUniformHeatmapPaletteProvider designed for usage with Heatmaps. The only distinction from the other interfaces is the shouldSetColors() method, which determines whether an IUniformHeatmapPaletteProvider implementation provides colors for every data point or it just updates colors passed in by a FastUniformHeatmapRenderableSeries object.
The following code snippet demonstrates how to create a custom IUniformHeatmapPaletteProvider:
The code above defines the IUniformHeatmapPaletteProvider called CustomUniformHeatMapProvider. Since its shouldSetColors() method returns False, CustomUniformHeatMapProvider has to provide a color for every data point. In this sample the color is picked based on the threshold value. The array with colors is created in the update() method and the current RenderPassData instance is updated to pass it to a FastUniformHeatmapRenderableSeries object for rendering:
The complete code sample can be found in the SciChart Android Example Suite.