jQuery flot - 当没有值时,不在 yaxis 上显示 -1

标签 jquery flot

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

enter image description here

提前致谢。

<小时/>

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

用于创建流程图的 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);

最佳答案

根据 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>

关于jQuery flot - 当没有值时,不在 yaxis 上显示 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32010505/

相关文章:

php - 在 JavaScript 中将字符串转换为数组

javascript - 将数组转换为 JSON

javascript - 如何在最后一个 css 类之后附加文本

javascript - 无论如何,从 $ (".box"获取索引项)

JQuery.UI.Tabs默认通过TabID选择

javascript - 如何在 Flot 中获取 x 轴起始值?

php - 格式化 json 数据以在 Flot 中使用

javascript - 如何向绘图中自动生成的刻度添加新刻度

javascript - float 条形图月份对齐问题

javascript - 带有多轴和复选框的 jQuery Flot