Chart interactions
Use cases
Chart interactions enable additional possibilities for end users to interact
with the data plotted within the chart area. The interactive options currently
supported within the TimeseriesChart
and the HistogramChart
are zoom-x, zoom
in, zoom out, select, and pan. To incorporate these interactions, the
ChartInteractions
subcomponent must be added inside the main component (e.g.
TimeseriesChart
). The chart interaction can then either be triggered using
keyboard shortcuts or by the optional chart toolbar. To enable the toolbar with
the chart interactions, the ChartToolbar
subcomponent must be added inside the
main component. To set initial position of the toolbar, the placement
prop can
be used.
Explore
The explore functionality is the default mode, and it allows you to inspect the
data within the chart. It includes an optional feature to select an area to zoom
along the x-axis. In order to enable this option it is necessary to add the
ChartInteractions.ZoomX
subcomponent to the ChartInteractions
component.
You can optionally trigger this mode from the keyboard by pressing E
while the
chart has focus.
Pan
Once a user has zoomed into the plotted data on a chart, panning can optionally
be enabled. Panning allows users to navigate left and right along the x-axis
whilst in a zoomed-in state. In order to enable this functionality, the
ChartInteractions.Pan
subcomponent needs to be added to the
ChartInteractions
component.
You can optionally trigger this mode from the keyboard by pressing P
while the
chart has focus.
Once you have triggered this mode:
- Pressing ← (Left Arrow) will pan to the left. You can also press
Shift
to increase the speed of pan movement. - Pressing → (Right Arrow) will pan to the right. You can also press
Shift
to increase the speed of pan movement.
Select
The select functionality allows users to select a specific area in the chart.
Selection can be used to display detailed information about data points inside
the selected area and/or to zoom in to the selected area (if the
ChartInteractions.ZoomX
subcomponent is added). In order to enable selection,
the ChartInteractions.Select
subcomponent needs to be added to the
ChartInteractions
component.
Select can be triggered by clicking and dragging on the chart area. To zoom in
on the selected area, press Enter
.
Upon selecting an area, the chart will display a tooltip with the selected
area's start and end timestamps, duration of the area, and amount of data points
and series. The tooltip can be dismissed by pressing Esc
. Similarly to the
basic tooltip, you can define custom actions.
Zoom-In and Zoom-Out
The zoom functionality allows users to zoom in to the chart's plotted data by a fixed point along the x-axis. The chart supports zoom in (incremental) and zoom out (decremental) actions.
In order to enable either of these zoom options on a chart it is necessary to
add the ChartInteractions.Zoom
subcomponent to the ChartInteractions
component.
You can optionally zoom in/out different ways by first focusing the chart:
- Pressing
Cmd
(Ctrl
in Windows) + the mouse wheel, will generate a zoom in/out trigger. - Pressing
Cmd
+ ↑ (Up Arrow) will zoom in. - Pressing
Cmd
+ ↓ (Down Arrow) will zoom out. - Pressing
Cmd
+ click will zoom in. - Pressing
Cmd
+ pressingShift
+ click will zoom out. - Pressing
Cmd
+ clicking and dragging draws a zoom area and zooms in on mouse up.
Reset
Reset will restore the chart to its initial state.
You can optionally trigger this action from the keyboard by pressing R
while
the chart has focus.
- Double-clicking on any part of the chart will trigger a reset.
It's also possible to programmatically trigger all the previously described
interactions by calling their methods on the TimeseriesChart
instance
reference. The available options are: exploreMode
, panMode
, zoomIn
,
zoomOut
and reset
.