将数组传递到折线图的数据时发出问题 [英] Issue while passing an array into the data of the line chart

查看:66
本文介绍了将数组传递到折线图的数据时发出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循获取json数据并将其存储到数组中的ajax代码-----



Following the ajax code that gets the json data and stores 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 --;
}

var count = Data.length;
var counter = 0;

while(count > 0){
DataResult[counter] =[Data[counter].COUNT];
counter++;
count --;
}

DrawChart();





我想在这里绘制图表 - --------





I am trying to draw the chart here ----------

function DrawChart(){

var ctx = document.getElementById("myChart").getContext("2d");

var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: LabelResult,
datasets: [{
label: '# of Votes',
data: [DataResult[0]],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:false
}
}]
}
}
});
}





标签正确呈现但数据未插入。即数组labelresult中的值给出了正确的标签,但数组dataresult中的值无法呈现图形



我尝试过:



尝试上面提到的代码,但无法使用数组通过chart.js



The lables are getting correctly rendered but the data in not getting inserted. i.e. values from array labelresult gives proper labels but values from array dataresult can not render the graph

What I have tried:

Tried the code mentioned above but not able to make use of an array to render a chart through chart.js

推荐答案

获取代码的工作示例,与代码进行比较,了解差异。

使用示例获取数据并使用该数据尝试代码,直至其工作。

使用调试器查看数据的差异。



调试器允许你逐行执行,检查变量,你会看到那里是一个停止做你期望的事情。

调试器 - 维基百科,免费的百科全书 [ ^ ]
Get a working sample of code, compare with your code, understand the differences.
Use the sample to get the data and try your code with that data until it works.
Use the debugger to see that is the difference in the data.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]


这篇关于将数组传递到折线图的数据时发出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆