B Seven
B Seven

Reputation: 45943

How to show only the last 100 candlesticks or hide the first 50 candlesticks in Highcharts Stock Chart?

I have a Highchart Stock chart that shows EMA's using Stock chart indicator.

Highchart Stock Chart

I do not want to use the rangefinder, as the chart should always show 100 candlesticks.

The EMA's work, but need to have extra candlesticks so that the first ones have EMA's. The API returns 100 candlesticks, but the first candlesticks do not have EMA's.

So, what is a good way to either:

  1. Hide the first 50 candlesticks or
  2. Only show the last 100 candlesticks?

I gather this might be done with the range selector, but not sure how to do it programatically.

Upvotes: 0

Views: 81

Answers (1)

ppotaczek
ppotaczek

Reputation: 39069

You need to use setExtremes method. You can call it for example in load event:

chart: {
  events: {
    load: function() {
      const points = this.series[0].points;
      const min = points[points.length - 101].x;

      this.xAxis[0].setExtremes(min, null, true, false);
    }
  }
}

Live demo: https://jsfiddle.net/BlackLabel/62djn43u/

API Reference: https://api.highcharts.com/class-reference/Highcharts.Axis#setExtremes

Upvotes: 2

Related Questions