我正在尝试使用react-chartjs-2
生成折线图。
通常,图表是由点构成的,但是我尝试生成正态分布图,因此它应该是连续的并由sigma
和mu
值构成。
我做出了妥协,并根据X轴间隔的边缘构造了任意N
点:
let N = 40;
let xValues = [];
let interval = (chart.data.max - chart.data.min) / N;
// Generate the X-axis values
for (let i = chart.data.min; i <= chart.data.max; i += interval) {
xValues.push(Math.round(i));
}
// Generate the Y-axis values by the normal distribution formula
let yValues = xValues.map(x => (
(2 * Math.PI * sigma ** 2) ** -0.5 * Math.exp(-0.5 * (x - mu) ** 2 / sigma ** 2)
));
let chartData = {
type: 'line',labels: xValues,datasets: [{
data: yValues,}]
}
但是可以使图表处于悬停状态吗,
- 图表不包含点数
- 与鼠标最接近的点被突出显示,就像在Google charts interface中一样?