Simple Crosshair Example
✓ Published0🌍 Public
CColinEberhardt
Last edited May 28, 2019
Created on Mar 27, 2017
A simple interactive crosshair tracks the mouse over a sine wave plotted with d3fc’s `chartCartesian` and `seriesSvgLine`. The crosshair, rendered by `annotationSvgCrosshair`, updates its x and y coordinates, which are displayed in a tooltip `div` positioned in the plot area. Mouse events are captured by the `fc.pointer` component, which supplies the coordinates to the crosshair via a multi-series mapping. The tooltip text is updated through the chart’s `decorate` pattern on enter and update selections.
AI-generated descriptionThis example demonstrates an interactive cross-hair.
- The crosshair itself is rendered via the crosshair annotation. Notice that the annotation itself is just a 'renderer', i.e. it does not handle mouse / touch events.
- The pointer component is used to add appropriate event handlers to the plot-area. The pointer component takes the mouse events and converts them into an array, which is the format required by the crosshair.
- The crosshair location is rendered to a
divelement that is added to the plot-area by decorating the cartesian chart. By adding the element via the enter selection, we ensure that it is added just once.
mit Licensed