【问题标题】:How to change highcahrts min and max selection behavior?如何更改 highcharts 最小和最大选择行为?
【发布时间】:2016-07-01 06:44:21
【问题描述】:

我有关于 highstock 的图表,scatter 类型。我选择了时间范围,然后 y 轴刻度发生了变化,但是 previous 可见点选择了最小值和最大值,而不仅仅是当前可见点。 如何改变这种行为?

例如,

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,则没有。

demo中,如果选择预设1,水平轴和底点之间有填充,当左边点隐藏时,可以改变比例(预设2)。

【问题讨论】:

  • 我希望在预设 1 上具有与预设 2 相同的比例范围,因为它具有相同的可见底点

标签: javascript highcharts highstock


【解决方案1】:

这是正常的 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/

最好的问候。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 2020-08-19
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 2013-04-03
    相关资源
    最近更新 更多