Skip to main content

Per-Point Coloring for Polar Column Series

Polar Column series can be colored per-point or per line-segment using the PaletteProvider API. To use this, we must create a class (TS) or object (JS) which implements or confirms to the IStrokePaletteProvider📘 and IFillPaletteProvider📘 interfaces. Then, apply this to the PolarColumnRenderableSeries.paletteProvider📘 property. This allows you to colour data-points based on values, or custom rules with infinite extensiblity.

First, let's create a PaletteProvider📘 class like this:

const {
DefaultPaletteProvider,
EStrokePaletteMode,
parseColorToUIntArgb
} = SciChart;
// or, for npm, import { DefaultPaletteProvider, ... } from "scichart"

// Custom PaletteProvider for column series which colours datapoints above a threshold
class ColumnPaletteProvider extends DefaultPaletteProvider {
public strokePaletteMode = EStrokePaletteMode.SOLID;
public threshold: number;
public stroke: number;
public fillColor: number;

constructor(threshold: number) {
super();
this.strokePaletteMode = EStrokePaletteMode.SOLID;
this.threshold = threshold;
this.stroke = parseColorToUIntArgb("#FF0000");
this.fillColor = parseColorToUIntArgb("#FF000077");
}

// This function is called for every data-point.
// Return undefined to use the default color for the line,
// else, return a custom colour as an ARGB color code, e.g. 0xFFFF0000 is red
overrideStrokeArgb(xValue: number, yValue: number, index: number, opacity: number, metadata: any) {
return yValue > this.threshold
? this.fillColor
: undefined;
}

// This function is called for every data-point
// Return undefined to use the default color for the fill, else, return
// a custom color as ARGB color code e.g. 0xFFFF0000 is red
overrideFillArgb(xValue: number, yValue: number, index: number, opacity: number, metadata: any) {
return yValue > this.threshold
? this.fillColor
: undefined;
}
}

Next, we can apply the PaletteProvider to the series. This can be done both with the programmatic API and the Builder API:

// Create and add a column series
const columnSeries = new PolarColumnRenderableSeries(wasmContext, {
fill: "rgba(176, 196, 222, 0.5)",
stroke: "rgba(176, 196, 222, 1)",
strokeThickness: 2,
dataPointWidth: 0.7,
dataSeries: new XyDataSeries(wasmContext, {
xValues: Array.from({ length: 20 }, (_, i) => i),
yValues: Array.from({ length: 20 }).map((_) => Math.random() * 10 + 5)
}),
paletteProvider: new ColumnPaletteProvider(10)
});

sciChartSurface.renderableSeries.add(columnSeries);

The code above results in a Polar Column Series with the following rule: change color if point is above yValue 10. The result is shown below:

See Also