仅将HighChart yAxis的min max设置为特定系列

时间:2018-09-09 04:51:32

标签: javascript highcharts candlestick-chart

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

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

动态滚动图表时,应调整yAxis的最小值/最大值。

我该怎么做?

jsfiddle simple code

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>

1 个答案:

答案 0 :(得分:0)

在'afterDrawChartBox'事件中,您可以将MAX(RegID)系列的最小值和最大值与GROUP BY方法一起使用:

SELECT
  f.RegID
 ,f.Name
 ,f.Team
FROM
  Football AS f
  JOIN
    (--The sub-query, sq, now gets the MAX ID
      SELECT
        MAX(f2.RegID) AS Max_RegID
      FROM
        Football AS f2
    ) AS sq
      ON
      sq.Max_RegID = f.RegID;

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

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