且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从javascript数组本身向图表js添加数据?

更新时间:2023-12-04 09:43:16

你必须创建数组,填充它们,只在对象中键入数组名称,而不需要用 []

You have to create the Array's, populate them, and only type the array name inside object without needing to surround it with [ and ]

示例:

var description = new Array();
description.push('a');
description.push('b');
var myvalues = new Array();
myvalues.push('c');
myvalues.push('d');
var barChartData = {
            labels: description,
            datasets: [
                {
                    fillColor: "rgba(220,220,220,0.5)",
                    strokeColor: "rgba(220,220,220,1)",
                    scaleOverride: true,
                    scaleSteps: 100,
                    stepValue: 1,
                    barShowStroke: false,
                    data: myvalues
                },
                {
                    fillColor: "rgba(151,187,205,0.5)",
                    strokeColor: "rgba(151,187,205,1)",
                    scaleOverride: true,
                    scaleSteps: 100,
                    barShowStroke: false,
                    stepValue: 1,
                    data: myvalues
                }
            ]

        }