简体   繁体   English

高档更改范围选择器更改的刻度间隔

[英]Highstock Change tick interval on range selector change

I am unable to get the tickinterval to update in the following Jsfiddle: https://jsfiddle.net/rarwarrar/5xgoqjst/4/ 我无法在以下Jsfiddle中更新tickinterval: https ://jsfiddle.net/rarwarrar/5xgoqjst/4/

Currently this: 目前这:

   xAxis: {
    events: {
    setExtremes: function(e) {
      if (e.rangeSelectorButton.text === "2Hour") {
         $('#chart').highcharts().xAxis[0].tickInterval= 2700000 //45 min
         $('#chart').highcharts().redraw()
       }
    }
    }
   },

Is not working. 不管用。

For instance can the tick interval be set to every 45 minutes once '2hour' is clicked? 例如,单击“ 2hour”后是否可以将刻度间隔设置为每45分钟一次?

You can use tickPositioner function for changing your tick positions after you set your extremes. 设置极值后,可以使用tickPositioner函数更改刻度位置。 You can use Axis.update() for updating tickPositions of this axis: 您可以使用Axis.update()更新此轴的tickPositions:

   setExtremes: function(e) {
     if (e.rangeSelectorButton.text === "2Hour") {
       this.update({
         tickPositioner: function() {
           var positions = [],
             info = this.tickPositions.info;
           for (var x = this.dataMin; x <= this.dataMax; x += 45 * 60 * 1000) {
             positions.push(x);
           };
           positions.info = info;
           return positions;
         }
       }, false)
     }
   }

Here you can see an example how it can work: https://jsfiddle.net/5xgoqjst/5/ 在这里,您可以看到一个示例它如何工作的: https : //jsfiddle.net/5xgoqjst/5/

You should be able to change your tickPositions on different ranges as well. 您还应该能够在不同范围内更改tickPositions。

Best regards. 最好的祝福。

You can, but that would be confusing to have text read "2hour" but actual time be 45 minutes. 您可以,但是将文本读为“ 2hour”会令人困惑,但实际时间为45分钟。 Why not add new button for this? 为什么不为此添加新按钮? In order for this to show there needs to be a minimum number of points but you can override with allButtonsEnabled . 为了显示此点,需要的点数最少,但可以使用allButtonsEnabled覆盖。 Here is what your rangeSelector could look like: 这是您的rangeSelector样子:

   rangeSelector: {
         allButtonsEnabled: true,
     buttons: [{
       type: 'hour',
       count: 2,
       text: '2Hour'
     }, {
       type: 'hour',
       count: 5,
       text: 'Week'
     }, {
       type: 'day',
       count: 1,
       text: '2Weeks'
     }, {
       type: 'minute',
       count: 45,
       text: '45 minutes'
     }],
     selected: 1,
     inputEnabled: false,
     buttonPosition: {
       x: 340
     },
     buttonSpacing: 10
   }

And here is a live demo of it. 这是它的现场演示

Maybe this could help someone, I updated an existing Fiddle ;-) 也许这可以帮助某人,我更新了现有的小提琴 ;-)

xAxis: {
  events: {
    setExtremes: function(e) {
      if (typeof(e.rangeSelectorButton) !== 'undefined') {
       // alert('count: ' + e.rangeSelectorButton.count + 'text: ' + e.rangeSelectorButton.text + ' type: ' + e.rangeSelectorButton.type);
        if (e.rangeSelectorButton.type === "week") {
          this.update({              
            tickInterval: 86400000, //1000*60*60*24 = 1 day
            minorTickInterval: 86400000
          }, false)
        }
      }
    }
  }
}

Then you will have to adapt it to your case of course. 然后,您将不得不使其适应您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM