这是我的JSFdle: https://jsfiddle.net/msuatp90/3/个
基本上,我希望将收入和过go 的收入叠加在一起,这样我就可以将一个时期与前一个时期进行比较.它将始终 for each 人提供相同的标记.
利润数据也是如此,我希望利润和过go 的利润重叠.
所有4个数据集每次都将具有完全相同的刻度数.但出于某种原因,它们并没有重叠,而是一个接一个地继续.
不过,工具提示似乎运行得很好.
以下是我现在拥有的完整代码:
let startGraph = function() {
let canvas = document.getElementById('chart');
let chart = new Chart(canvas.getContext('2d'), {
type: 'line',
data: {
datasets: [{
label: 'Revenue',
data: {
"2023-03-01": 250,
"2023-03-02": 488,
"2023-03-03": 358,
"2023-03-04": 255,
"2023-03-05": 895
},
borderColor: '#ff6384',
xAxisID: 'x',
},
{
label: 'Profit',
data: {
"2023-03-01": 125,
"2023-03-02": 156,
"2023-03-03": 195,
"2023-03-04": 98,
"2023-03-05": 466
},
borderColor: '#36a2eb',
xAxisID: 'x',
},
{
label: 'Past Revenue',
data: {
"2023-02-24": 280,
"2023-02-25": 456,
"2023-02-26": 665,
"2023-02-27": 288,
"2023-02-28": 499
},
borderColor: '#fa829b',
xAxisID: 'x1',
},
{
label: 'Past Profit',
data: {
"2023-02-24": 125,
"2023-02-25": 198,
"2023-02-26": 265,
"2023-02-27": 101,
"2023-02-28": 221
},
borderColor: '#76c1f5',
xAxisID: 'x1',
}
]
},
options: {
elements: {
point: {
radius: 0,
hoverRadius: 0,
hitRadius: 3,
},
line: {
borderWidth: 2,
},
},
responsive: true,
maintainAspectRatio: false,
interaction: {
intersect: false,
mode: 'index',
},
stacked: false,
scales: {
y: {
ticks: {
display: true,
beginAtZero: true,
}
},
x: {
position: 'bottom',
ticks: {
display: false,
},
},
x1: {
position: 'top',
ticks: {
display: false,
},
grid: {
drawOnChartArea: false,
},
},
},
plugins: {
legend: {
display: true,
position: 'bottom',
labels: {
boxWidth: 8,
boxHeight: 8,
useBorderRadius: true,
borderRadius: 3,
usePointStyle: false,
pointStyleWidth: 0,
padding: 7,
font: {
size: 11
}
}
},
},
}
});
}