Dataset._meta [0] .dataset在ChartJS中为null [英] Dataset._meta[0].dataset is null in ChartJS
本文介绍了Dataset._meta [0] .dataset在ChartJS中为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用图表JS显示每个条形的值.我看到了该线程并遵循,但是出现了错误.
I'm trying to show the value of each bar using chart JS. I saw this thread and followed, but I got an error.
链接:如何显示数据值或索引标签在ChartJs(最新版本)中
var options = {
events: false,
showTooltips: false,
animation: {
duration: 0,
onComplete: function(){
var ctx = this.chart.ctx;
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontFamily, 'normal', Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.textBaseLine = 'bottom';
this.data.datasets.forEach(function(dataset){
console.log(dataset);
for(var i = 0; i < dataset.data.length; i++){
var model = dataset._meta[0].dataset._children[i]._model;
ctx.fillText(dataset.data[i], model.x, model.y - 5);
}
});
}
}
};
错误
TypeError:dataset._meta [0] .dataset为空
TypeError: dataset._meta[0].dataset is null
推荐答案
正如您在链接的帖子(您链接的帖子)上所看到的那样,答案包含如下代码:
As you can see on the linked post (you linked that post), the answer contains code like this:
for (var i = 0; i < dataset.data.length; i++) {
for(var key in dataset._meta)
{
var model = dataset._meta[key].data[i]._model;
ctx.fillText(dataset.data[i], model.x, model.y - 5);
}
}
此代码已被接受.试试这个.另外,您尝试使用具有相同的null错误问题.
This code is the accepted. Try this. The other, you try to use has the same null error problem.
这篇关于Dataset._meta [0] .dataset在ChartJS中为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文