Skip to content

Crosshair

A crosshair with value labels on the axes. By default it snaps to the nearest node (snap), together with the tooltip and highlighting.

Modular build

When building with grafit-charts/core, the crosshair is a separate module: register(crosshairModule).

ts
import { getData } from './data';
import type { ChartOptions } from 'grafit-charts';

export function createOptions(): ChartOptions {
  return {
    data: getData(),
    title: { text: 'Crosshair' },
    subtitle: { text: 'hover over the plot area' },
    series: [{ type: 'line', xField: 'month', yField: 'value', name: 'Value' }],
    crosshair: { enabled: true },
    legend: { enabled: false },
  };
}
ts
export function getData() {
  return [
    { month: 'Jan', value: 412 },
    { month: 'Feb', value: 438 },
    { month: 'Mar', value: 471 },
    { month: 'Apr', value: 449 },
    { month: 'May', value: 502 },
    { month: 'Jun', value: 535 },
    { month: 'Jul', value: 518 },
    { month: 'Aug', value: 560 },
  ];
}
OptionTypeDefaultDescription
enabledbooleanenable (presence of the block → enabled)
snapbooleantruesnap to the nearest node
strokeColorValuetheme mutedline color
strokeWidthPixels1line width
lineDashPixels[][4, 3]dash pattern
label.enabledbooleantruevalue labels on the axes