【发布时间】:2020-04-28 19:16:46
【问题描述】:
我想知道如何在 chartjs 中单击按钮时以 html 表格的形式查看图表数据。 我已经使用 chartjs 实现了折线图, xaxis 代表颜色 yaxis代表投票和积分
工作小提琴:https://jsfiddle.net/miyavv/ehqrL20o/ 我想将图表显示为表格
Color | # of Votes | # of Points
Red 12 7
Blue 19 11
... and so on
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
reverse: false
}
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
//html
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>
【问题讨论】:
-
很遗憾,您的问题不清楚,请提供更多信息或沙盒示例。
-
@Alex 感谢回复,我想将图表数据显示为 html 表格,
-
@Alex 我已经更新了我的问题和小提琴
-
@SciFiThief 的回答有什么问题? “图表作为表格”是什么意思?请画出您想要的结果并附上问题。可以帮助您明确您的意图
标签: javascript jquery reactjs datatable chart.js