Skip to main content

Per-Point Coloring for Polar Line Series

Polar Line 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 PolarLineRenderableSeries.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"

type TRule = (yValue: number, xValue: number) => boolean;

class ThresholdLinePaletteProvider extends DefaultPaletteProvider {
public rule: TRule;
public stroke: number;
public strokePaletteMode = EStrokePaletteMode.SOLID;

constructor(stroke: string, rule: TRule) {
super();
this.strokePaletteMode = EStrokePaletteMode.SOLID;
this.rule = rule;
this.stroke = parseColorToUIntArgb(stroke);
}

overrideStrokeArgb(xValue: number, yValue: number, index: number, opacity: number, metadata: IPointMetadata) {
return this.rule(yValue, xValue)
? this.stroke
: undefined;
}
}

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

const polarLine = new PolarLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, {
xValues: Array.from({ length: 34 }, (_, i) => i),
yValues: Array.from({ length: 34 }, (_, i) => 1 + i / 5)
}),
stroke: "green",
strokeThickness: 5,
interpolateLine: true,
paletteProvider: new ThresholdLinePaletteProvider(
"#FFFFFF",
(yValue, xValue) => Math.floor(xValue / 3) % 2 === 0
)
});
sciChartSurface.renderableSeries.add(polarLine);

The code above results in a Polar Line Series with the following rule: change color on every 3rd point. The result is shown below:

  • We create a ThresholdLinePaletteProvider class that extends DefaultPaletteProvider📘
  • The strokePaletteMode📘 is set to SOLID📘 since we want abrupt color changes based on a condition, not a GRADIENT📘
  • We override overrideStrokeArgb📘 to return another stroke color when our rule is met: Math.floor(xValue / 3) % 2 === 0
  • When the method returns undefined, the default stroke color is used; otherwise, the custom color is applied
  • The interpolateLine📘 is set to true to create smooth curved segments that follow the polar coordinate system

See Also