简体   繁体   中英

highstock chart only set the max value of xAxis

I want to only set the max value of xAxis. I get this value from session value. I want to display stockchart. The selected range of xAxis is set(from session value) and not changing. How to link the max xAxis value to the rangeSelectorButton and input range selector or and navigator. Click range button or input range or navigator, the max value of xAxis doesn't change.

If i use the following code, I have to sent the value of both min and max value.

$('#container').highcharts('StockChart', {

  title: {
    text: 'AAPL Stock Price'
  },
  xAxis: {
    events: {
      SetExtremes: function (e) {
        if (e.trigger == "rangeSelectorButton") {
          setTimeout(function () {
            var end = 1293091200000;
            Highcharts.charts[0].xAxis[0].setExtremes(1198681756385, end)
          }, 1);

        }
      },
    }
  },
  series: [{
    name: 'AAPL',
    data: data,
    tooltip: {
      valueDecimals: 2
    }
  }]
});

How can I only set the max value? The reason why I want this, because I get a date from session value, then I can choose different button range selector to show past week or past 1 month or past 3 month chart.

In case you want to set the max value of the extreme (selected range on navigator) without changing the min extreme, you can first retrieve the current extreme and set the same value back:

// Assume the chart instance is stored in variable 'chart'
var extremes = chart.xAxis[0].getExtremes();
chart.xAxis[0].setExtremes(extremes.min, yourMaxValue);

First of all setExtremes , not SetExtremes .

Second thing, calling setExtremes in setExtremes callback makes infinite loop.

I advice to disable rangeSelector from Highcharts, generate your own HTML buttons, and add click event where you will call chart.xAxis[0].setExtremes(previous_min, your_max_value); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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