chart.js散点图-数组中的数据集数据未显示数据

时间:2020-03-23 21:16:20

标签: chart.js

我是js的超级初学者,想用以前定义的数组(recentEventsCounter1)填充散点图的数据部分。

以下不起作用:

var recentEventsCounter1 = [{ x: -10, y: 0 },{ x: 0, y: 10 }]; [...] data: [recentEventsCounter1]

这项工作没有问题: data: [{ x: -10, y: 0 },{ x: 0, y: 10 }]

整个代码:

    var recentEventsCounter1 = [{ x: -10, y: 0 },{ x: 0, y: 10 }]; 
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'scatter',
    data: {
        datasets: [{
            label: 'Scatter Dataset',
            backgroundColor: 'Green',
            borderColor: 'Green',
            borderDash: [1,2,3,4],
            borderDashOffset: 10,
            showLines: false,
            spanGap: true, 
            borderStyleCap: "butt", 
            fill: false, 
            steppedline: true ,
           borderWidth: 10,
            pointBackgroundColor: ['yellow', 'blue', 'red', 'green', 'orange', 'indigo'],
            data: [
              //{ x: -10, y: 0 },{ x: 0, y: 10 } or recentEventsCounter1 ?
            ]
        }]
    },

0 个答案:

没有答案