仅将HighChart yAxis的min max设置为特定系列 [英] Set HighChart yAxis's min max to a specific series only

查看:105
本文介绍了仅将HighChart yAxis的min max设置为特定系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个股价烛台系列,和一个与烛台系列共享yAxis的线系列。默认情况下,API会自动将图表的yAxis范围设置为两个系列的最小值/最大值(烛台系列,线系列)的最小值/最大值

I have a stock price candlestick series And a line series that share yAxis with the candlestick series. By default, the API automatically set chart's yAxis range to the min/max of two series's min/max(candlestick series, line series)

但我想显示烛台系列比折线图更重要。因此,即使图表的yAxis最小值/最大值切断了线序列,也应仅限制其烛台序列。

But I want to show the candlestick series more importantly than line chart. So, chart's yAxis min/max should be limited only the candlestick series even if it cut the line series off.

并且图表的yAxis最小值/最大值应进行调整是动态滚动的。

And the yAxis min/max should be adjusted when the chart is scrolled dynamically.

我该怎么做?

jsfiddle简单代码

var chartData = [
  [1473687000000, 102.65, 105.72, 102.53, 105.44],
  [1473773400000, 107.51, 108.79, 107.24, 107.95],
  [1473859800000, 108.73, 113.03,  108.6, 111.77],
  [1473946200000, 113.86, 115.73, 113.49, 115.57]
];
    
var avgData = [
  [1473687000000, 250],
  [1473773400000, 300],
  [1473859800000, 280],
  [1473946200000, 290]
];

$(function() {
  Highcharts.stockChart('container', {
    // title: {text: '---'},
    rangeSelector: {
      buttons: [
        // { type: 'hour', count: 1, text: '1h' },
        { type: 'day', count: 1, text: '1d' },
        // { type: 'all', count: 1, text: 'All' }
      ],
      selected: 1,
      //inputEnabled: true
    },
    xAxis: [{
      type: 'datetime',
    
    }],
    yAxis: [{
      labels: {
        align: 'right',
        x: -3
      },
      title: {text: 'OHLC'},
      height: '100%',
      lineWidth: 2,
      resize: {
        enabled: true
      }
    }], 

    plotOptions: {
      candlestick: {
        downColor: 'blue',
        upColor: 'red',
        dataGrouping: {
          enabled: false,
        }
      }
    },

    series: [{
      name: 'ohlc',
      type: 'candlestick',
      data: chartData,
    }, {
      name: 'avg',
      type: 'line',
      data: avgData,
    }]
  });
});

dic#container {height: 100%; width: 100%;}

<script src="//code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="//code.highcharts.com/stock/highstock.js"></script>
<script src="//code.highcharts.com/stock/modules/drag-panes.js"></script>
<script src="//code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container"></div>

推荐答案

在'afterDrawChartBox'事件中,可以将 setExtremes 方法与min以及烛台系列的最大值:

In 'afterDrawChartBox' event, you can use setExtremes method with min and max values from candlestick series:

Highcharts.addEvent(Highcharts.Chart, 'afterDrawChartBox', function(e) {
    var candlestick = this.series[0];
    this.yAxis[0].setExtremes(candlestick.dataMin, candlestick.dataMax, true, false);
});

实时演示: https://jsfiddle.net/BlackLabel/520km1wv/

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

这篇关于仅将HighChart yAxis的min max设置为特定系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆