JavaScript Custom Cursor with Stacked Y Dashboard - Editor

This example serves as an example for custom data cursor implementation in stacked Y charts dashboard, where there are several XY charts stacked vertically on each other.

Custom cursors can be required for different purposes - like major structural changes or very application specific styling requirements.

If lesser changes to default cursors are required then please see read about different methods of configuring cursor behavior - ChartXY API reference has good links and explanations to follow.

In this case, the X Axis of each chart are synchronized, and when user mouse is above the chart the data of all series Y coordinates is shown at the respective X coordinate.

Each LineSeries contains 100 000 unique data points, coming to a total of 300 000 data points. Regardless, the interaction with cursor is instantaneous.

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.
chart.onSeriesBackgroundMouseMove((_, event) => {
  // `event` is a native JavaScript event, which packs the active mouse location in `clientX` and `clientY` properties.
  const mouseLocationClient = { x: event.clientX, y: event.clientY };

  // Before using client coordinates with LCJS, the coordinates have to be translated relative to the LCJS engine.
  const mouseLocationEngine = chart.engine.clientLocation2Engine(

  // 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(
    // Source coordinate system.
    // 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.

The default cursor can only display data from one chart at a time, but using the LCJS methods, the cursor can be configured to display data from all independent charts at the same time.

More custom cursor examples can be found by looking for "cursor" tag in the Interactive Examples gallery.