using array values in chart.js data and label field(在 chart.js 数据和标签字段中使用数组值)
问题描述
我希望将数组的值传递给 chart.js 数据集的数据和标签字段.
I wish to pass values of an array to the data and label fields of the chart.js dataset.
这里是 ajax 调用成功获取 json 数据的代码.我获取 json 数据并将其存储到一个数组中.
Here the code from success of ajax call made to fetch json data. I fetch the json data and store it into an array.
Data = jQuery.parseJSON(result);
var count = Data.length;
var counter = 0;
while(count > 0) {
LabelResult[counter] =[Data[counter].TIME];
counter++;
count --;
}
现在我希望将此标签值用于标签字段.
Now i wish to use this label values into the labels filed.
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [LabelResult],
datasets: [{
label: '# of Votes',
data: [DataResult],
borderWidth: 1
}]
}
});
但似乎有一些问题,数据没有在图表上呈现
But there seems some issue and the data is not getting rendered on the chart
推荐答案
LabelResult是一个数组,改变
LabelResult is an array, change
labels: [LabelResult]
到
labels: LabelResult
还有:
data: [DataResult]
到
data: DataResult
喜欢:
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: LabelResult,
datasets: [{
label: '# of Votes',
data: DataResult,
borderWidth: 1
}]
}
});
这篇关于在 chart.js 数据和标签字段中使用数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 chart.js 数据和标签字段中使用数组值


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01