Skip to main content

Drawing PointMarkers on Series (Scatter markers)

Every data point of a Scatter, Line, Bubble, Mountain, Spline, Error or Column Series may be marked with a PointMarker📘. So, not just limited to scatter series, you can apply a pointmarker to line series, or error bars to display a repeated marker at the X,Y point.

info

Simply set BaseRenderableSeries.pointMarker📘 = new EllipsePointMarker()📘 to apply a scatter point to most series types.

Several different types of PointMarker are available in SciChart.js:

Below we're going to show some options how to use different types of PointMarker in SciChart.

// Create a chart with X,Y axis
const { sciChartSurface, wasmContext } = await SciChartSurface.create(divElementId, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { growBy: new NumberRange(0.0, 0.4) }));

// Create some data
const { xValues, yValues1, yValues2, yValues3, yValues4, yValues5 } = createData();

const commonOptions = { width: 11, height: 11, strokeThickness: 2 };

// Add a line series with EllipsePointMarker
sciChartSurface.renderableSeries.add(
new XyScatterRenderableSeries(wasmContext, {
pointMarker: new EllipsePointMarker(wasmContext, {
...commonOptions,
fill: "#0077FF99",
stroke: "LightSteelBlue"
}),
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: yValues1 })
})
);

// Add a scatter series with SquarePointMarker
sciChartSurface.renderableSeries.add(
new XyScatterRenderableSeries(wasmContext, {
pointMarker: new SquarePointMarker(wasmContext, {
...commonOptions,
fill: "#FF000099",
stroke: "Red"
}),
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: yValues2 })
})
);

// Add a scatter series with TrianglePointMarker
sciChartSurface.renderableSeries.add(
new XyScatterRenderableSeries(wasmContext, {
pointMarker: new TrianglePointMarker(wasmContext, {
...commonOptions,
fill: "#FFDD00",
stroke: "#FF6600"
}),
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: yValues3 })
})
);

// Add a scatter series with CrossPointMarker
sciChartSurface.renderableSeries.add(
new XyScatterRenderableSeries(wasmContext, {
pointMarker: new CrossPointMarker(wasmContext, {
...commonOptions,
stroke: "#FF00FF"
}),
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: yValues4 })
})
);

// Add a scatter series with Custom Image using SpritePointMarker
const imageBitmap = await createImageAsync("https://www.scichart.com/demo/images/CustomMarkerImage.png");

sciChartSurface.renderableSeries.add(
new XyScatterRenderableSeries(wasmContext, {
pointMarker: new SpritePointMarker(wasmContext, {
image: imageBitmap
}),
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: yValues5 })
})
);

This results in the following output:

IsLastPointOnly mode for Pointmarkers

The PointMarker type has a property isLastPointOnly📘. When true, only the last point of a scatter series is drawn. This can be useful to highlight a point in say a sweeping ECG chart.

Additional Tips for PointMarkers

Custom markers can be created using the SpritePointMarker📘 type, which allows loading a custom image as a marker. This uses the helper function createImageAsync📘 which allows loading of a PNG file either from URL, or locally hosted / imported image.

tip

For a TypeScript / npm & webpack example you can see the JavaScript Custom PointMarkers Chart example in the SciChart.js demo.