我有一个非常简单的highcharts js图表,在x轴上有日期,在y轴上有值。此代码可以正常工作:

chart = new Highcharts.Chart({
    chart: {
        renderTo: 'chart_container',
        type: 'line',
    },
    xAxis: {
        type: 'datetime',
            dateTimeLabelFormats: {
                day: '%e / %b'
            }
    },
    yAxis: {
            title: {
                text: null
            },
            tickInterval: 1,
            tickmarkPlacement: 'on',
            min: 1,
            max: 5
    },
    series: [{
            name: 'serie_1',
            pointInterval: 24 * 3600 * 1000, // one day
            pointStart: Date.UTC(2011, 11, 22),
            data: [
                2, 3, 5, 4, null, 4, 4, 4, 4, 3, 2, 2, 1, 2, 2, null
            ]
   }]
});


当触发某些操作时,我还有一个事件会更改图表的数据:

function reloadChart(){
    $.get('/my/ajax/link/', { ajax_param: 10 },
        function(data){
            // HOW TO GET THIS TO WORKS??? series.pointStart is readonly
            chart.series[0].pointStart = data.newPointStart;

            chart.series[0].setData(data.data, true);
        }
    );
}


我的问题是:图表初始化后,如何更新我的系列[0] .pointStart?

最佳答案

我会重新考虑。从y值序列创建x,y点比使用pointStartpointInterval选项更容易。

startDate = Date.UTC(2010, 0, 1);
createData = function(beginDate){
    someData = [];
    for (var i = 0; i < 11; i++){
     someData.push([beginDate + (3600 * 1000 * 24 * i), Math.random() * 100]);
    }
    return someData;
}

....

series: [{
        data: createData(startDate)
    }]


然后在您的函数中:

 nextDay = function(){
    startDate += 3600 * 1000 * 24;
    chart.series[0].setData(createData(startDate), true);
 }


工作提琴here

07-24 18:51