I would like to be able (upon the chart load) show the 'crosshair' on a specific point on the chart.
I have the crosshair at the moment displaying correctly crosshair with data from 9 y axis (x axis is time one).
I have searched the documentation and examples but was unable to see any such thing.
Crosshair documentation: https://uber.github.io/react-vis/documentation/api-reference/crosshair https://github.com/uber/react-vis/blob/master/docs/crosshair.md
React vis event handlers: https://github.com/uber/react-vis/blob/master/docs/interaction.md
React vis examples: https://uber.github.io/react-vis/
import {
XYPlot,
XAxis,
YAxis,
VerticalGridLines,
HorizontalGridLines,
LineSeries,
Crosshair
} from 'index';
const DATA = [
[{x: 1, y: 10}, {x: 2, y: 7}, {x: 3, y: 15}],
[{x: 1, y: 20}, {x: 2, y: 5}, {x: 3, y: 15}]
];
export default class DynamicCrosshair extends React.Component {
constructor(props) {
super(props);
this.state = {
crosshairValues: []
};
}
/**
* Event handler for onMouseLeave.
* @private
*/
_onMouseLeave = () => {
this.setState({crosshairValues: []});
};
/**
* Event handler for onNearestX.
* @param {Object} value Selected value.
* @param {index} index Index of the value in the data array.
* @private
*/
_onNearestX = (value, {index}) => {
this.setState({crosshairValues: DATA.map(d => d[index])});
};
render() {
return (
<XYPlot onMouseLeave={this._onMouseLeave} width={300} height={300}>
<VerticalGridLines />
<HorizontalGridLines />
<XAxis />
<YAxis />
<LineSeries onNearestX={this._onNearestX} data={DATA[0]} />
<LineSeries data={DATA[1]} />
<Crosshair
values={this.state.crosshairValues}
className={'test-class-name'}
/>
</XYPlot>
);
}
}
In the event handlers section, there is a list of event handlers but those require user action. I would like the crosshair position being changed based on the state passed to it.
Based on what I already saw, I am not sure if this is at all possible? I don't need the tooltip part so I can live without it, all I need is really the crosshair.
Thank you for any help with this / answer to this.