如何使用chart.js传递变量?

时间:2019-03-01 06:59:20

标签: javascript chart.js

我想通过变量将变量传递到另一个页面,就像我们使用ajax即(类型:post和data:data)传递变量一样。

function showGraph1() {
  {
    $.post("data.php",
      function(data) {
        var name = [];
        var marks = [];
        for (var i in data) {
          name.push(data[i].NAME);
          marks.push(data[i].PERCENTAGE);
        }
        var chartdata = {
          labels: name,
          datasets: [{
            labels: ["#000000", "Blue", "Yellow", "Green", "#E07C0AF"],
            data: marks
          }]
        };
        var graphTarget = $("#graphCanvas1");
        var barGraph = new Chart(graphTarget, {
          type: 'doughnut',
          data: chartdata,
        });
      });
  }
}

0 个答案:

没有答案