如何改变highcahrts的最小和最大选择行为

How to change highcahrts min and max selection behavior?

本文关键字:选择 何改变 改变 highcahrts      更新时间:2023-09-26

我有一个图表在高股票,与scatter类型。我选择时间范围,然后y轴尺度改变,但最小和最大选择以前可见点,而不仅仅是当前可见点。如何改变这种行为?

例如,

series : [{
    id: 'id',
    data : [100,101,102,0,103,104,105],
    type: "scatter",
    marker : {
        enabled : true,
        radius : 20
    }
}]

如果我看103,104,105点,y轴上是0,如果104,105点,没有。

在演示中,如果选择预设1,在水平轴和底部点之间有填充,当左点隐藏时,它允许改变比例(预设2)。

这是正常的Highcharts功能,用于从可见范围外的第一个点计算dataMin和dataMax。您可以通过更改getextrees方法来更改此行为:

Highcharts.Series.prototype.getExtremes = function(yData) {
  var xAxis = this.xAxis,
    yAxis = this.yAxis,
    xData = this.processedXData,
    UNDEFINED = undefined,
    yDataLength,
    activeYData = [],
    activeCounter = 0,
    xExtremes = xAxis.getExtremes(), // #2117, need to compensate for log X axis
    xMin = xExtremes.min,
    xMax = xExtremes.max,
    validValue,
    withinRange,
    x,
    y,
    i,
    j;
  yData = yData || this.stackedYData || this.processedYData || [];
  yDataLength = yData.length;
  for (i = 0; i < yDataLength; i++) {
    x = xData[i];
    y = yData[i];
    // For points within the visible range, not including the first point outside the
    // visible range, consider y extremes
    validValue = y !== null && y !== UNDEFINED && (!yAxis.isLog || (y.length || y > 0));
    withinRange = this.getExtremesFromAll || this.options.getExtremesFromAll || this.cropped ||
      ((xData[i] || x) >= xMin && (xData[i] || x) <= xMax);
    if (validValue && withinRange) {
      j = y.length;
      if (j) { // array, like ohlc or range data
        while (j--) {
          if (y[j] !== null) {
            activeYData[activeCounter++] = y[j];
          }
        }
      } else {
        activeYData[activeCounter++] = y;
      }
    }
  }
  this.dataMin = arrayMin(activeYData);
  this.dataMax = arrayMax(activeYData);
};

这里你可以看到一个例子,它是如何工作的:http://jsfiddle.net/85t2yjyz/6/

问好。