当没有值时,是否可以防止 flot 在 y 轴上显示 -1?
提前致谢。
<小时/>//编辑:我正在为某些服务器创建统计图表(每小时访问次数)。有些服务器一天没有访问,所以流程图上没有数据。
用于创建流程图的 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
指定 min
和 max
属性:
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 } });
这是演示 min
和 max
值的代码片段。
$.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/