我正在使用来自 React-Vis 的提示,但即使我将提示传递给它应该再次绘制的值,它也超出了范围。如何确保它位于垂直条高度之上?
或此处的完整代码:
export default class Example extends React.Component {
state = {
hintValue: ""
};
_onNearestX = (value) => {
this.setState({ hintValue: value });
};
render() {
return (
<div>
<XYPlot width={300} height={300} stackBy="y" xType="ordinal">
<VerticalGridLines />
<HorizontalGridLines />
<XAxis />
<YAxis />
<VerticalBarSeries
cluster="Q2"
color="red"
data={[
{ x: 1, y: 5 },
{ x: 2, y: 15 }
]}
onNearestXY={this._onNearestX}
/>
<VerticalBarSeries
cluster="Q2"
color="grey"
data={[
{ x: 1, y: 2 },
{ x: 2, y: 11 }
]}
onNearestXY={this._onNearestX}
/>
<VerticalBarSeries
cluster="Q1"
color="green"
data={[
{ x: 1, y: 8 },
{ x: 2, y: 16 }
]}
onNearestXY={this._onNearestX}
/>
<VerticalBarSeries
cluster="Q1"
color="lightgreen"
data={[
{ x: 1, y: 3 },
{ x: 2, y: 12 }
]}
onNearestXY={this._onNearestX}
/>
<VerticalBarSeries
cluster="Q1"
color="yellow"
data={[
{ x: 1, y: 1 },
{ x: 2, y: 1 }
]}
onValueClick={(datapoint, event) => {
console.log(datapoint, event); // Some SVG element
}}
onNearestXY={this._onNearestX}
/>
{this.state.hintValue !== "" && (
<Hint value={this.state.hintValue}>
<div className="hint">
<p>X: {this.state.hintValue.x}</p>
<p>Y: {this.state.hintValue.y}</p>
</div>
</Hint>
)}
</XYPlot>
</div>
);
}
}
const rootElement = document.querySelector("#root");
if (rootElement) {
render(<Example />, rootElement);
}