Highcharts:如何在Ajax调用上更新Plotoptions pointStart?

时间:2014-07-01 09:03:09

标签: javascript jquery ajax charts highcharts

我的MVC Web应用程序中有一个简单的图表。现在我有一些过滤器会更新其click事件的图表。实际上,click事件将使用ajax调用来更新图表。

这是我的图表:

 $('#performance-cart').highcharts({
    chart: {
        type: 'area', backgroundColor: '#f5f7f7', style: { fontFamily: 'Roboto, Sans-serif', color: '#aeafb1' },
        animation: {
            duration: 1500,
            easing: 'easeOutBounce'
        }
    },
    xAxis: {
        type: 'datetime',
        labels: { style: { color: '#aeafb1' } }
    },
    yAxis: {
        min: 0, max: 50, tickInterval: 10, gridLineColor: '#ebeded', gridLineWidth: 1,
        title: { text: '' }, lineWidth: 0, labels: { align: 'right', style: { color: '#aeafb1' } }
    },
    title: { text: '' },
    tooltip: {
        useHTML: true, headerFormat: '<h3 style="color:#ffffff;font-weight:300;padding: 3px 12px;">{point.y:,.1f}</br>',
        backgroundColor: '#515757', pointFormat: '{series.name}'
    },
    legend: {
        itemStyle: { color: '#838589' }, symbolWidth: 12, symbolHeight: 5, itemWidth: 80, symbolRadius: 0,
        itemMarginBottom: 10, backgroundColor: '#f5f7f7', verticalAlign: 'top', borderWidth: 0, x: -498, y: 10
    },
    plotOptions: {
        area: {
            fillOpacity: 0.2, cursor: 'pointer', marker: {
                symbol: 'circle', fillColor: '#FFFFFF', lineWidth: 2, lineColor: null,
                allowPointSelect: true
            }
        },
        line: {
            fillOpacity: 0.2, cursor: 'pointer', marker: {
                symbol: 'circle', fillColor: '#FFFFFF', lineWidth: 2, lineColor: null,
                allowPointSelect: true
            }
        },
        column: {
            fillOpacity: 0.2, cursor: 'pointer', marker: {
                symbol: 'circle', fillColor: '#FFFFFF', lineWidth: 2, lineColor: null,
                allowPointSelect: true
            }
        },
        series: {
            pointStart: myIssueResolvedStartDate,
            pointInterval: 24 * 3600 * 1000 // one day
        }
    },
    series: [{
        name: 'Issues', color: '#ff3806',
        data: myIssueData,
        marker: { states: { hover: { fillColor: '#ff3806', lineColor: '#ffffff', lineWidth: 2 } } }
    }, {
        name: 'Resolved', color: '#1da9dd',
        data: myResolvedData,
        marker: { states: { hover: { fillColor: '#1da9dd', lineColor: '#ffffff', lineWidth: 2 } } }
    }]
});

现在在我的ajax调用中,我做了类似的事情来更新图表:

var chart = $('#performance-cart').highcharts();
chart.options.plotOptions.series.pointStart = newDate; \\newDate = 1404086400000
chart.series[0].setData(issue, true);
chart.series[1].setData(resolve, true);

问题是,chart.options.plotOptions.series.pointStart = newDate;没有更新pointStart。我检查了newDate变量中的值,并以UTC格式显示了完美的日期。系列数据正在更新。

我相信我写的语法错误或者是针对pointStart的。如果有人能够指出问题,我真的很感激。

1 个答案:

答案 0 :(得分:5)

您无法实时更新plotOptions(也许有一些黑客入侵,但我们不提供官方API方法)。但是,您可以更新每个系列,如下所示:

var chart = $('#performance-cart').highcharts();
chart.series[0].update({
    data: issue,
    pointStart: newDate
}, true);
chart.series[1].update({
    data: resolve,
    pointStart: newDate
}, true);