问题描述
结果和标签都来自服务器,但它们看起来没问题.当我运行此代码时,我没有得到任何图形.我正在使用 CDN 中的 chart.js.
Both results and labels come from the server but they seem alright. When I run this code I don't get any graphics. I'm using the chart.js from the CDN.
澄清一下,结果和数据都来自代码.它们没有像示例中那样进行硬编码.
Clarification, both results and data come from the code. They are not hardcoded as they look in the example.
我得到的错误说:
t.ticks.map 不是函数
t.ticks.map is not a function
无法获取未定义或空引用的属性跳过"
Unable to get property 'skip' of undefined or null reference
代码:
<canvas id="myChart" width="400" height="400"></canvas>
var ctx = document.getElementById("myChart").getContext("2d");
var result = [0, 0, 0];
var lbls = ['A', 'B', 'C'];
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: lbls.split(','),
datasets: [{
label: '# of Votes',
data: result
}]
}
});
也欢迎任何关于其他图表实用程序的建议.
Any suggestion about another chart utility is welcome too.
推荐答案
标签需要一个数组变量,但是 var lbls = $('#lbls').html()
返回一个字符串,所以用 ',' 分开就可以了
The labels requires a array variable but the var lbls = $('#lbls').html()
returns a string so splitting it with ',' will do the job
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: lbls.split(','),
datasets: [{
label: '# of Votes',
data: [20, 10]
}]
}
});
这篇关于Chart.js t.ticks.map 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!