admin管理员组文章数量:1316371
Currently I use this to add data to my charts:
targetChart.addData(value,targetDataSetIndex,"");
because I thought that this would add data to a specific set, adding an empty label.
But this doesnt work.
I then tried doing it myself by introducing a new method in the Chart.js script, like this:
addDataValueToSpecificDataSet :function(value,datasetIndex)
{
this.datasets[datasetIndex].points.push(new this.PointClass({
value: value,
label: label,
x: this.scale.calculateX(this.scale.valuesCount + 1),
y: this.scale.endPoint,
strokeColor: this.datasets[datasetIndex].pointStrokeColor,
fillColor: this.datasets[datasetIndex].pointColor
}));
}
But when executing it isnt found. Where in Chart.JS do I need to put this so that it is accessible from the outside? Or can someone please tell me how im supposed to add data to a chart with multiple datasets one by one. I cant find it in the documentation which covers everything BUT adding and removing data.
Currently I use this to add data to my charts:
targetChart.addData(value,targetDataSetIndex,"");
because I thought that this would add data to a specific set, adding an empty label.
But this doesnt work.
I then tried doing it myself by introducing a new method in the Chart.js script, like this:
addDataValueToSpecificDataSet :function(value,datasetIndex)
{
this.datasets[datasetIndex].points.push(new this.PointClass({
value: value,
label: label,
x: this.scale.calculateX(this.scale.valuesCount + 1),
y: this.scale.endPoint,
strokeColor: this.datasets[datasetIndex].pointStrokeColor,
fillColor: this.datasets[datasetIndex].pointColor
}));
}
But when executing it isnt found. Where in Chart.JS do I need to put this so that it is accessible from the outside? Or can someone please tell me how im supposed to add data to a chart with multiple datasets one by one. I cant find it in the documentation which covers everything BUT adding and removing data.
Share Improve this question asked Oct 24, 2016 at 13:06 RaviorRavior 6113 gold badges11 silver badges30 bronze badges1 Answer
Reset to default 4This works for me (you probably just need to add update):
function addData() {
myBarChart.data.labels[12] ="2017";
myBarChart.data.labels[13] ="2018";
myBarChart.data.datasets[0].data[12] = 500;
myBarChart.data.datasets[0].data[13] = 600;
myBarChart.update();
}
CodePen: Add/Remove adjust data Chart.js
本文标签: javascriptChartJS How to add Data to a specific datasetStack Overflow
版权声明:本文标题:javascript - Chart.JS: How to add Data to a specific dataset - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742003433a2411477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论