答案 0 :(得分:4)
要在工具提示中添加特定标签(日期)中的所有数据,您需要在图表选项中将工具提示mode
设置为index
,如下所示:
options: {
tooltips: {
mode: 'index'
},
...
}
<强>ᴅᴇᴍᴏ强>
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
datasets: [{
label: 'LINE 1',
data: [3, 1, 4, 2, 5],
backgroundColor: 'rgba(0, 119, 290, 0.2)',
borderColor: 'rgba(0, 119, 290, 0.6)'
}, {
label: 'LINE 2',
data: [4, 2, 3, 5, 1],
backgroundColor: 'rgba(0, 119, 290, 0.1)',
borderColor: 'rgba(0, 119, 290, 0.6)'
}]
},
options: {
tooltips: {
mode: 'index'
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>
&#13;