javascript - 如何更改 highcharts 最小和最大选择行为?

标签 javascript highcharts

我有 highstock 图表,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,则没有。

demo ,如果选择预设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/

最好的问候。

关于javascript - 如何更改 highcharts 最小和最大选择行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38138740/

相关文章:

javascript - 从 JavaScript 中的索引向后遍历数组

javascript - 如何用新敌人重置游戏?

javascript - 如何在 HighCharts 中绘制对数刻度的饼图?

javascript - 新项目与本地 react 但错误

javascript - 取消选中另一个按钮上的选中复选框单击

javascript - Ionic2:当你来到页面时,你如何选择要关注的输入?

javascript - chrome 背景选项卡中的网页时出现 Highcharts 错误

javascript - 谷歌折线图 : drag to adjust value

javascript - 加入区域 Highcharts

javascript - Highcharts 折线图向下钻取无法正常工作