Chart.js t.ticks.map不是一个函数 [英] Chart.js t.ticks.map is not a function
问题描述
结果和标签都来自服务器,但它们似乎没问题。当我运行此代码时,我没有得到任何图形。我正在使用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
无法获取未定义或空引用的属性'skip'
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不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!