Dear SciChart Team,
I am attempting to create a custom PaletteProvider for PointMarker that does not trigger each time the visible range changes. I have referred to the documentation here: https://sabai-scichart.local/documentation/js/current/typedoc/interfaces/ipointmarkerpaletteprovider.html.
I have implemented the new class as follows:
class NewTradePaletteProvider {
constructor(inputChart) {
this.inputChart = inputChart;
}
onAttached(parentSeries) {
this.parentSeries = parentSeries;
}
onDetached() {
this.parentSeries = undefined;
}
get isRangeIndependant() {
return true;
}
overridePointMarkerArgb(xValue, yValue, index, opacity, metadata) {
const fillValue =
index % 2 == 0
? parseColorToUIntArgb("#00AB55")
: parseColorToUIntArgb("#2195F2");
return { stroke: undefined, fill: fillValue };
}
}
However, the overridePointMarkerArgb method is still being called every time the visible range changes. Could you kindly advise if there is an issue with my approach?
Best regards,
Phat
- Pham Phat asked 2 years ago
- last edited 2 years ago
- You must login to post comments
Hi Phat,
I’m assuming the reason you want to avoid this is to improve performance?
If so – I would recommend moving this code out into the constructor:
class NewTradePaletteProvider {
constructor(inputChart) {
this.inputChart = inputChart;
this.color0 = parseColorToUIntArgb("#00AB55");
this.color1 = parseColorToUIntArgb("#2195F2");
}
// ...
overridePointMarkerArgb(xValue, yValue, index, opacity, metadata) {
const fillValue = index % 2 == 0 ? this.color0 : this.color1;
return { stroke: undefined, fill: fillValue };
}
This will improve the performance dramatically.
There is also another (as yet undocumented) feature in SciChart.js called an IAdvancedPaletteProvider. This will allow you to create and cache colours so that the calculations of which color to apply are not called each time the chart redraws.
We’re working on the docs for this now – when we have something online will post back.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 2 years ago
- You must login to post comments
Yeah! I am looking to improve performance; however, when the data series reaches around 60,000 data points, there is a significant decrease in performance. Could you suggest any alternative approaches?
Best regards,
Phat
- Pham Phat answered 2 years ago
- last edited 2 years ago
Did you try the suggestion of moving parseColorToUIntArgb out to the constructor? This is quite an expensive call so I suggest to pre-cache colors. Also, David’s suggestion of shouldUpdatePalette() to return false. Also, we are working on docs / examples for IAdvancedPaletteProvider which allows you to pre-calculate an array of colours for bars once.
Oh I posted this comment prior to David’s suggestion of implementing shouldUpdatePalette(). It has significantly improved performance. I hope the team completes version 4 soon!
- You must login to post comments
Hi
Add the following to your paletteProvider:
shouldUpdatePallete() {
return false;
}
We had to back off making this false by default in version 3 to make sure existing paletteProviders always worked. We hope to change this in v4 so we can get better reuse of palette calculations.
Regards
David
- David Burleigh answered 2 years ago
- You must login to post comments
Please login first to submit.

