簡體   English   中英

如何更改Highcahrts的最小和最大選擇行為?

[英]How to change highcahrts min and max selection behavior?

我有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。 您可以通過更改getExtremes方法來更改此行為:

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/

最好的祝福。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM