实时跟踪中的highcharts和highstock之间的差异以及具有最大值的xAxis

时间:2014-04-07 07:33:11

标签: javascript jquery charts highcharts highstock

我遇到了highstock的问题。 我试图将实时数据添加到我的图表中。 但是当设置max xAxis时,我注意到来自highchart和highstock的不同行为。

例如,如果xAxis max为100且我添加值20: - 在highcharts one中,该值在图表的前半部分添加 - 在高股票期间,最后在图表的边缘添加价值

看看这两个正在运行的例子:

highcharts:http://jsfiddle.net/Jy83b/

highstock:http://jsfiddle.net/mE6XM/

我需要highstock图表中的highcharts行为.. 我该如何解决?

谢谢!

highcharts code

  var pippo = (new Date()).getTime() + 60000;
  $(function () {
      $(document).ready(function() {
          Highcharts.setOptions({
              global: {
                  useUTC: false
              }
          });

          var chart;
          $('#container').highcharts({
              chart: {
                  type: 'spline',
                  animation: Highcharts.svg, // don't animate in old IE
                  marginRight: 10,
                  events: {
                      load: function() {

                          // set up the updating of the chart each second
                          var series = this.series[0];
                          setInterval(function() {
                              var x = (new Date()).getTime(), // current time
                                  y = Math.random();
                              series.addPoint([x, y], true, false);
                          }, 1000);
                      }
                  }
              },
              title: {
                  text: 'Live random data'
              },
              xAxis: {
                  type: 'datetime',
                  tickPixelInterval: 150,
                  max: pippo
              },
              yAxis: {
                  title: {
                      text: 'Value'
                  },
                  plotLines: [{
                      value: 0,
                      width: 1,
                      color: '#808080'
                  }]
              },
              tooltip: {
                  formatter: function() {
                          return '<b>'+ this.series.name +'</b><br/>'+
                          Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                          Highcharts.numberFormat(this.y, 2);
                  }
              },
              legend: {
                  enabled: false
              },
              exporting: {
                  enabled: false
              },
              series: [{
                  name: 'Random data',
                  data: (function() {
                      // generate an array of random data
                      var data = [],
                          time = (new Date()).getTime(),
                          i;

                      for (i = -19; i <= 0; i++) {
                          data.push({
                              x: time + i * 1000,
                              y: Math.random()
                          });
                      }
                      return data;
                  })()
              }]
          });
      });

  });

高股代码

  var pippo = (new Date()).getTime() + 60000;
  $(function () {
      $(document).ready(function() {
          Highcharts.setOptions({
              global: {
                  useUTC: false
              }
          });

          var chart;
          $('#container').highcharts('StockChart',{
              chart: {
                  type: 'spline',
                  animation: Highcharts.svg, // don't animate in old IE
                  marginRight: 10,
                  events: {
                      load: function() {

                          // set up the updating of the chart each second
                          var series = this.series[0];
                          setInterval(function() {
                              var x = (new Date()).getTime(), // current time
                                  y = Math.random();
                              series.addPoint([x, y], true, false);
                          }, 1000);
                      }
                  }
              },
              title: {
                  text: 'Live random data'
              },
        exporting: {
            enabled: false
        },
        rangeSelector: {
              enabled: false
        },
        navigator : {
            enabled : false
        },
          scrollbar : {
            enabled : false
        },
        legend : {
            enabled : false
        },
              xAxis: {
                  type: 'datetime',
                  tickPixelInterval: 150,
                  max: pippo
              },
              yAxis: {
                  title: {
                      text: 'Value'
                  },
                  plotLines: [{
                      value: 0,
                      width: 1,
                      color: '#808080'
                  }]
              },
              tooltip: {
                  formatter: function() {
                          return '<b>'+ this.series.name +'</b><br/>'+
                          Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                          Highcharts.numberFormat(this.y, 2);
                  }
              },
              legend: {
                  enabled: false
              },
              exporting: {
                  enabled: false
              },
              series: [{
                  name: 'Random data',
                  data: (function() {
                      // generate an array of random data
                      var data = [],
                          time = (new Date()).getTime(),
                          i;

                      for (i = -19; i <= 0; i++) {
                          data.push({
                              x: time + i * 1000,
                              y: Math.random()
                          });
                      }
                      return data;
                  })()
              }]
          });
      });

  });

解决了!

已添加序数:false为xAxis

1 个答案:

答案 0 :(得分:2)

为您的xAxis设置添加ordial:false:

xAxis: {
            type: 'datetime',
            tickPixelInterval: 150,
            max: pippo,
            ordinal: false 
        },

然后你会有同样的行为。