在x轴尺度上重新缩放y轴最小/最大

Flot Re-scale Yaxis min/max on X-axis scale

本文关键字:缩放 最大 新缩放      更新时间:2023-09-26

我有一个很长的unixtime, value Array,用于启动一个流程图,以及一些按钮来改变比例,我似乎无法做到的是让y轴随着x比例的变化而缩放。

下面是一个示例图表:http://jsfiddle.net/U53vz/

var datarows = //Data Array Here
var options =  { series: { lines: { show: true }, points: { show: true } },
        grid: { hoverable: true,clickable: false, },
        xaxis: { mode: "time", min: ((new Date().getTime()) - 30*24*60*60*1000), max: new Date().getTime(), }
    };
function castPlot() {
window.PLOT = $.plot("#placeholder", [{ data: dataRows }], options
);
};

在官方示例中,缩放是自动的,并且在y轴上未指定:http://www.flotcharts.org/flot/examples/axes-time/index.html

我能想到的唯一替代方法是遍历数据集并在每次按下按钮时计算新的Y min/max。除非我破坏了一些非常明显的默认函数。

在计算y-scale时,flot不只是查看"可见"数据,而是查看整个数据集。由于数据点仍然存在,y min/max尊重它们。所以你的选项是:

  1. 将系列数据子集缩小到所需范围,并让flot对x和y进行缩放。
  2. 根据您的建议,在y轴上计算您自己的min/max。

如果你的绘图比现在更复杂(特别是如果你开始设置点击/悬停事件),我也建议你切换到重画,而不是重新绘制你的绘图。

var opts = somePlot.getOptions();
opts.xaxes[0].min = newXMin;
opts.xaxes[0].max = newXMax;
opts.yaxes[0].min = newYMin;
opts.yaxes[0].max = newYMax;
somePlot.setupGrid();
somePlot.draw();

编辑