jQuery plot - 没有值时不在 y 轴上显示 -1

jQuery flot - don't display -1 on yaxis when there are no value

当没有值时,是否可以防止 flot 在 yaxis 上显示 -1?

提前致谢。


// 编辑:我正在为某些服务器创建统计图表(每小时访问次数)。每天有一些服务器没有访问,所以flot图表没有数据。

Javascript 用于创建我的图表:

function onOutboundReceived(data) {
    var length = data.length;
    var finalData = data;
    var options = {
        series: {
             lines: {
                 show: true,
                 lineWidth: 2, 
                 fill: true,
                 fillColor: {
                 colors: [{
                     opacity: 0.2
                 },{
                     opacity: 0.01
                 }]
             } 
        },
        points: {
            show: true
        },
            shadowSize: 2
                },
                legend:{
                  show: false
                },
                grid: {
                    labelMargin: 10,
                    axisMargin: 500,
                    hoverable: true,
                    clickable: true,
                    tickColor: "rgba(255,255,255,0.22)",
                    borderWidth: 0
                },
                yaxis: {
                    ticks: 5,
                    tickDecimals: 0
                },
                xaxis: {
                    ticks: 24,
                    tickDecimals: 0
                }
            };
            $.plot($("#stats-"+HSIDarr[i]), finalData, options);

您可以在绘图选项中指定 y 轴的最小值和最大值,请参阅 documentation

根据 API doc,您可以为 axis:

指定 minmax 属性

The options "min"/"max" are the precise minimum/maximum value on the scale. If you don't specify either of them, a value will automatically be chosen based on the minimum/maximum data values.

这样做的例子在情节初始化中:

$.plot($("#placeholder"), [ [[0, 0], [1, 1]] ], { yaxis: { max: 1 } });

这是演示 minmax 值的片段。

$.plot($("#graph"), [ [[0, 0], [1, 1]] ], { yaxis: { max: 1, min: 1 } });
#graph {
  width: 600px;
  height: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.js"></script>

<div id="graph" style="width:600px;height:300px"></div>