高图表中的动态值问题


Dynamic values issue in high chart

我想在xAxis Category和Series Data中使用动态值。但是当我通过数组使用时,我的图表不起作用,也没有发生错误。

这是我的代码:

var visitor_id = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var total_visit_count = new Array(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
$('#graph_main').highcharts({
   title: {
                text: 'Monthly Average Temperature',
                x: -20 //center
            },
            subtitle: {
                text: 'Source: WorldClimate.com',
                x: -20
            },
            xAxis: {
                categories: [visitor_id]
            },
            yAxis: {
                title: {
                    text: 'Temperature'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                valueSuffix: 'C'
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: [{
                name: 'Tokyo',
                data: [total_visit_count]
            }]
})

您的错误就在这里

data: [total_visit_count]

应该是

data: total_visit_count

total_visit_count是一个数组,data接受一个数组但您将整个数组作为数组中的数组传递。

希望这能帮助你