新的Highcharts.chart返回一个图表数组[undefined,a.chart]

时间:2016-12-27 18:26:20

标签: javascript charts highcharts

我有一个创建新Highcharts的功能。但是,当我创建一个新图表并在之后记录Highcharts.charts数组时,它会在数组中显示一个未定义的元素。我怎样才能防止这种情况发生?

<!-- Div to hold the occ chart -->
<div id="dialog2">
    <div id="canvas2" width="600" height="400"></div>
</div>

$("#divId").click(function() {
    createChart('canvas2', occChartOpts);
    theDialog2.dialog('open');   
})

//general function to create chart
function createChart(id, options) {
    return new Highcharts.chart(id, options);
}

//options object for occupancy chart
var occChartOpts = {
    chart: {
        type: 'areaspline'
    },
    title: {
        text: 'Hourly Home vs Office Occupancy'
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        verticalAlign: 'top',
        x: 150,
        y: 100,
        floating: true,
        borderWidth: 1,
        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
    },
    xAxis: {
        categories: [
            '12am - 4am',
            '4am - 8am',
            '8am - 12pm',
            '12pm - 4pm',
            '4pm - 8pm',
            '8pm - 12am'
        ],
    },
    yAxis: {
        title: {
            text: 'Percent'
        }
    },
    tooltip: {
        shared: true,
        valueSuffix: '%'
    },
    credits: {
        enabled: false
    },
    plotOptions: {
        areaspline: {
            fillOpacity: 0.5
        }
    },
    series: [{
        name: 'Home',
        data: [95, 55, 10, 15, 45, 90]
    }, {
        name: 'Office',
        data: [5, 45, 90, 85, 55, 10]
    }]
}

0 个答案:

没有答案