Skip to content
silverpoint
Documentation menu

Concepts

Interaction & readouts

Charts are explorable by pointer and keyboard out of the box. You can listen to the item under the pointer or focus, react to a selection, and replace the built-in readout.

Try it

Hover, or focus the chart with Tab and use the arrow keys. This readout is a custom template: tooltip_template("{datum.hour} h · {value} hits").

Hits per hourHits per hour
Hits per hour
hourhits
0018
0214
0411
0616
0834
1058
1271
1466
1674
1888
2062
2241

Events

ReactVueAngularReflex
Item under pointer/focusonActiveChange@active-change(activeChange)on_active_change
Selection (click, Enter, Space)onSelect@select(select)on_select
Drill-down (treemap, sunburst)onRootChange@root-change(rootChange)on_root_change
Custom readouttooltip={fn}#tooltip slotng-template spTooltiptooltip_template()

The item is { seriesKey, index, datum, value, point: { x, y } }, and the active item is null when it leaves.

In your code

tsx
import { useState } from 'react';
import { LineChart } from '@silverpoint/react/line-chart';

export function Explorer({ data }: { data: { hour: string; hits: number }[] }) {
  const [active, setActive] = useState<string>('—');
  return (
    <>
      <LineChart
        data={data}
        xKey="hour"
        valueKey="hits"
        title="Hits per hour"
        onActiveChange={(item) => setActive(item ? `${item.datum.hour}: ${item.value}` : '—')}
        onSelect={(item) => console.log('selected', item.datum)}
        tooltip={(item) => <strong>{item.value} hits</strong>}
      />
      <p>Under the pointer: {active}</p>
    </>
  );
}