0
我正在使用chart.js v.2。库,我试图在用户悬停在图表点上时将光标样式更改为“指针”。 (我将使用这个吧,饼图,折线图)。在charts.js v.2中似乎应该支持这个选项。但我无法在任何地方找到示例。如何将光标样式更改为悬停在图表上的指针?
编辑: 我没有提到,我正在使用图表反应,更具体的我使用这个react wrapper。
我正在导入例如图线import { Line } from 'react-chartjs-2';
class ChartTimelineChart extends Component {
constructor(props){
super(props);
this.options = {
responsive: true,
maintainAspectRatio: false,
animation: {
easing: 'easeOutCirc',
duration: 1000
},
pointStyle : 'circle',
scales: {
xAxes: [{
display: true,
gridLines: {display: false},
scaleLabel: {display: true}
}],
yAxes: [{
display: true,
gridLines: {display: false},
ticks: {beginAtZero:true},
scaleLabel: {display: true}
}]
},
tooltips: {
displayColors: false
},
legend: false
};
searchChart(elem, props, data) {
//Something...
}
render(){
return (
(this.props.selectedYears.length)
? ( <div>
<Line data={this.props.selectedYearsData}
redraw={true}
options={this.options}
getElementAtEvent={elem => this.searchChart(elem, this.props, this.props.selectedYearsData)} />
</div>)
: <Line data={{datasets: [], labels: []}}
redraw={true}
options={this.options} />
)
}
};
我已经改变了光标的风格在画布上悬停的CSS ,但这不是我想要的。我希望光标在POINTS上更改样式(例如,使用折线图显示工具提示的位置)...无论如何......感谢 –
这正是上述代码所发生的情况。我刚刚在一个折线图中进行了测试,光标转向指向点并返回箭头。你试过这个吗? –
请检查更新的问题,并让我知道我的情况是否以及如何使用您的解决方案。谢谢! –