如何在javascript中动态地向数组中添加项目

nas*_*eeg 1 javascript jquery highcharts

首先,我是一个全新的javascript新手,所以请耐心等待.我有以下脚本使用Highchart框架绘制饼图

$(function() {
    var options = {
        colors: ["#66CC00", "#FF0000", "#FF6600"],
        chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: true
        },
        title: {
            text: 'Host Status'
        },
        tooltip: {
            formatter: function() {
                return '<b>' + this.point.name + '</b>: ' + this.total;
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>' + this.point.name + '</b>';
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'service status',
            data: []
        }]
    }

    var chart;
    options.series.data.push('['
    Service Ok ',   45.0]')
    $(document).ready(function() {
        chart = new Highcharts.Chart(options)
    });

});?
Run Code Online (Sandbox Code Playgroud)

我想要做的是动态地将值series.data作为对象数组加载到数组中.这里有什么问题,是否有更好的方法将数据加载到数据阵列?

McG*_*gle 5

系列属性是一个数组,所以你需要把它写这样的(增加一个数据点系列):

options.series[0].data.push( ["Service Ok", 45.0 ]);
Run Code Online (Sandbox Code Playgroud)

我正在看这个JS小提琴.