简体   繁体   中英

colors are not updated when updating chart

Since version 2.9.0+ colors are not updated when updating chart. Till version 2.8.0 this works. How to handle updates in 2.9.0+ version?

This is how I try to update my chart. chart = the chart d = the data from my get request

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/

In your code, data is actually a dataset and must be defined as an object but not as an array. This problem can be solved by changing var data = []; to var data = {}; .

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

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

Please have a look at your amended JSFiddle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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