2011-12-09 89 views
0

我使用HighCharts庫來繪製非常大的數據集(即〜18,000點)。我在後端使用量化來將點數減少到合理的大小(小於200)。當用戶選擇圖表的一部分時,它向服務器發出ajax請求並接收採樣頻率較高的新集合。但是,在plotOptions中更改pointInterval時,它實際上並不會更改顯示圖表上的間隔。更改HighCharts pointInterval創建圖表後

這些是我使用,使圖表我的選擇:

options = { 
    chart: { 
     renderTo: settings.highchartId, 
     zoomType: 'x', 
     spacingRight: 20, 
     events: { 
      load: getChartData, 
      selection: zoomChart, 
     } 
    }, 
    title: { 
     text: Drupal.settings.openfitcharts.title 
    }, 
    subtitle: { 
     text: document.ontouchstart === undefined ? 
       'Click and drag in the plot area to zoom in' : 
       'Drag your finger over the plot to zoom in' 
    }, 
    xAxis: { 
     allowDecimals: false, 
     title: { 
      text: Drupal.settings.openfitcharts.xAxisTitle 
     } 
    }, 
    yAxis: { 
     title: { 
      text: Drupal.settings.openfitcharts.yAxisTitle 
     }, 
     startOnTick: false, 
     showFirstLabel: false 
    }, 
    tooltip: { 
     shared: true      
    }, 
    legend: { 
     enabled: false 
    }, 
    series: [{ 
     type: "line", 
     data: [], 
    }], 
    plotOptions: { 
     line: { 
      marker: { 
       enabled: false, 
       states: { 
        hover: { 
         enabled: true, 
         radius: 5 
        } 
       } 
      }, 
      pointInterval: 1, 
      pointStart: 0, 
     } 
    } 
}; 

這是我使用來獲取數據的功能:

function getChartData() { 
    activityId = settings.seriesData.activityId; 
    trackType = settings.seriesData.type; 

    jQuery.getJSON(OPENFIT_DATA_URL, {op: 'TrackHandler.getTrackData', actid: activityId, type: trackType}, function(returnData) { 
     console.log(returnData); 
     console.log(chart); 
     if (returnData != null) { 
      chart.options.plotOptions.line.pointInterval = returnData.interval; 
      chart.options.plotOptions.line.pointStart = returnData.start; 
      chart.xAxis[0].adjustTickAmount(); 
      chart.series[0].setData(returnData.data, true); 
     } 
    }); 
} 

回答

0

更改系列的pointInterval對象不是plotOptions:

chart.series[0].pointInterval = 24 * 3600 * 1000; 
chart.series[0].setData([29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],true); 

See this fiddle.

1

您還可以使用series.update()一次更新所有選項,請參閱:http://jsfiddle.net/7XcMn/

chart.series[0].update({ 
     pointInterval: 100, 
     data: [100, 200, 300] 
    });