简体   繁体   English

colors 更新图表时未更新

[英]colors are not updated when updating chart

Since version 2.9.0+ colors are not updated when updating chart.由于版本 2.9.0+ colors 在更新图表时没有更新。 Till version 2.8.0 this works.直到 2.8.0 版本才有效。 How to handle updates in 2.9.0+ version?如何处理 2.9.0+ 版本的更新?

This is how I try to update my chart.这就是我尝试更新图表的方式。 chart = the chart d = the data from my get request chart = 图表 d = 我的 get 请求中的数据

function addBarData(chart, d) {
  var data = [];
  data.backgroundColor = [
    color(window.chartColors.red).alpha(0.5).rgbString(),
    color(window.chartColors.blue).alpha(0.5).rgbString(),
    color(window.chartColors.green).alpha(0.5).rgbString()
  ];
  data.borderColor = [
    window.chartColors.red,
    window.chartColors.blue,
    window.chartColors.green
  ];
  data.borderWidth = 1;
  data.data = d.values;
  data.label = d.label;
  chart.data.datasets.push(data);
  chart.update();
}

My complete code: https://jsfiddle.net/wge1bj80/我的完整代码: https://jsfiddle.net/wge1bj80/

In your code, data is actually a dataset and must be defined as an object but not as an array.在您的代码中, data实际上是一个dataset ,必须定义为 object 而不是数组。 This problem can be solved by changing var data = [];这个问题可以通过改变var data = []; to var data = {};var data = {}; . .

function addBarData(chart, d) {
  var data = {};
  ...
}

function addPieData(chart, d) {
  var data = {};
  ...
}

Please have a look at your amended JSFiddle .请查看您修改后的JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM