如何在不强制 Flot 中的 y 轴为零的情况下填充折线图?

How can I fill a line chart without forcing the y axis to zero in Flot?

我有一个具有以下系列配置的 Flot 图设置:

{
    series: {
        shadowSize: 0,
        lines: {
            // fill: true,
            fillColor: { colors: [{ opacity: 0 }, { opacity: 0.5 }] }
        }
    }
}

没有将 fill 设置为 true,我得到了这个结果,这是我想要的布局,它自动将 y 轴的下限设置为最低数据点值附近:

如果我将 fill 设置为 true,我得到了我想要的渐变填充,但 y 轴下降到零:

希望这只是一个快速的配置修复,也欢迎就此问题的更好标题提出建议。

将您的代码更改为:

series: {
    shadowSize: 0,
    lines: {
        fill: true,
        zero: false,
        fillColor: { colors: [{ opacity: 0 }, { opacity: 0.5 }] }
    }
}

来自documentation

Area and bar charts normally start from zero, regardless of the data's range. This is because they convey information through size, and starting from a different value would distort their meaning. In cases where the fill is purely for decorative purposes, however, "zero" allows you to override this behavior. It defaults to true for filled lines and bars; setting it to false tells the series to use the same automatic scaling as an un-filled line.