This example serves as an example for creating a custom cursor for XY charts.
Custom cursors can be required for different purposes - like major structural changes or very application specific styling requirements.
Custom cursors are most importantly based on LCJS methods that allow solving nearest data points in series from any supplied location. Custom user interactions and data point solving require solid understanding of different coordinate systems in web and LCJS, which is the primary reason this example exists;
// Add custom action when user moves mouse over series area.
);// Now that the coordinates are in the correct coordinate system, they can be used// to solve data points, or further translated to any Axis.// (1) Translate mouse location an Axis.const mouseLocationAxis =translatePoint(
mouseLocationEngine,// Source coordinate system.
chart.engine.scale,// Target coordinate system.
);// (2) Solve nearest data point from a series to the mouse.const nearestDataPoint = series.solveNearestFromScreen(mouseLocationEngine);// `nearestDataPoint` is either `undefined`, or an object // which contains a collection of information about the solved data point.});
In this example, the custom cursor visual is created with dynamically injected HTML and CSS.
The same approach could be used for interacting with any UI framework, idea being that LCJS is used for solving the data point and translating the location to the document, where any HTML element can be absolute positioned with left & top style.
The location and visibility of result table is animated with a CSS transition.
More custom cursor examples can be found by looking for "cursor" tag in the Interactive Examples gallery.