我第一次使用Chart JS,我想为同一个标签显示多个数据点。我是否可以在不创建多个数据集的情况下执行此操作。此外,我将仅在运行时知道数据集的数量。
使用案例:对于x轴上的每个点(标签),在y轴上绘制多个点
现在我正在做这样的事情
var ctx = $(element);
var myChart = new Chart(ctx, {
type: graphType,
data: {
labels: labels,
datasets: [
{
label: labelTeacher,
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(100,149,237,0.5)",
borderColor: "rgba(100,149,237,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(58,95,205,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(100,149,237,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [65, 59, 90, 81, 56, 55, 40]
},
{
label: labelVedantu,
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(255,165,0,0.5)",
borderColor: "rgba(255,165,0,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(255,165,0,1)",
pointBackgroundColor: "rgba(255,255,255,1)",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(255,165,0,1)",
pointHoverBorderColor: "rgba(250,228,196,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [28, 48, 40, 19, 96, 27, 100]
}
]
},
我们说我有相同标签集的多个数据数组,有没有办法在不添加新数据集的情况下每次执行
答案 0 :(得分:0)
当您说' show'时,您指的是图表的呈现方式,或者"工具提示"当您将鼠标悬停在图表上时会出现?
如果是后者,请查看模式:' index'选项/工具提示的设置,如下所述:
http://www.chartjs.org/docs/latest/general/interactions/modes.html#interaction-modes