[英]custom label title for scatter in React-ChartJS-2
I try to make a scatter plot using React-ChartJS-2.我尝试使用 React-ChartJS-2 散点图 plot。 The basic setting gives only the values of the x-value and the y-value of the point in the plot. Is there any way to show the label for the point in the plot?
基本设置只给出了plot中点的x值和y值。有没有办法显示plot中点的label?
I lookup around and found the code seemed to work, but it did not.我环顾四周,发现代码似乎可以工作,但事实并非如此。
const optionsScatterPlot = {
plugins: {
tooltip: {
callbacks: {
title: function (tooltipItem:any, data:any) {
const dataLabel = dataScatterPlot.labels[tooltipItem.index];
return dataLabel;
}
}
},
},
};
const Scatter = () => {
return (
<div>
<Box maxWidth="lg" margin="auto" >
AdEfficiency
</Box>
<Scatter options={optionsScatterPlot} data={dataScatterPlot} />
</div>
)
}
Add label title to either of the axes like so:将 label 标题添加到任一轴,如下所示:
const options = {
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'label for Y'
}
},
x: {
beginAtZero: true,
title: {
display: true,
text: 'label for X'
}
},
},
};
the text property is the text label to be displayed on the axes. text属性是要在坐标区上显示的文本 label。 'options' variable is what you pass to the options prop.
'options' 变量是您传递给 options 道具的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.