website/versioned_docs/version-5.1/plugins/pane-primitives.md
In addition to Series Primitives, the library now supports Pane Primitives. These are essentially the same as Series Primitives but are designed to draw on the pane of a chart rather than being associated with a specific series. Pane Primitives can be used for features like watermarks or other chart-wide annotations.
Pane Primitives can be added to a chart using the attachPrimitive method on the IPaneApi interface. Here's an example:
const chart = createChart(document.getElementById('container'));
const pane = chart.panes()[0]; // Get the first (main) pane
const myPanePrimitive = new MyCustomPanePrimitive();
pane.attachPrimitive(myPanePrimitive);
To create a Pane Primitive, you should implement the IPanePrimitive interface. This interface is similar to ISeriesPrimitive, but with some key differences:
paneViews method is used to define what will be drawn on the chart pane.Here's a basic example of a Pane Primitive implementation:
class MyCustomPanePrimitive {
paneViews() {
return [
{
renderer: {
draw: target => {
// Custom drawing logic here
},
},
},
];
}
// Other methods as needed...
}
For more details on implementing Pane Primitives, refer to the IPanePrimitive interface documentation.