[英]How to plot time values in Flot Graph
I am using Flot Graph Api to plot graphs, I want to plot time values in bar charts.我正在使用Flot Graph Api绘制图形,我想在条形图中绘制时间值。
My table look like some thing similar to this我的桌子看起来像这样的东西
My X-Axis should be list of Reasons and Y-Axis should be time variables.我的 X 轴应该是原因列表,Y 轴应该是时间变量。 My Graph should be some thing like this.
我的图表应该是这样的。
but i get something like this, because of the Json object is packed wrongly.但我得到了这样的东西,因为 Json 对象被错误地打包。
How to plot graph for time values in如何绘制时间值的图形
My plot JS code is我的情节 JS 代码是
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$.getJSON('ReasonByTime.txt', function(json) {
//succes - data loaded, now use plot:
var plotarea = $("#placeholder");
var dataBar=json.data;
$.plot(plotarea , [
{
data: dataBar,
bars: { show: true},
legend: {show: true},
yaxis: {
mode: 'time',
timeformat: "%y/%m/%d",
min: ( new Date('2012/01/01') ).getTime(),
max: ( new Date('2020/01/01') ).getTime(),
minTickSize: [1, 'hour']
}
}
]
);
});
}); });
and my current Json object is like this.而我目前的 Json 对象就是这样的。
{"data":[[0,5202],[0,19620],[0,82920],[0,240],[0,75720],[0,3060],[0,72840]],"label":"Tea break"}
Since i'm new to flot i'm struck up with this work, i did some research but i can't able to solve my problem.因为我是新来的,所以我对这项工作很感兴趣,我做了一些研究,但我无法解决我的问题。 Can someone help me out.
有人可以帮我吗。
The problem isn't with the JSON, but with your data itself.问题不在于 JSON,而在于您的数据本身。 Your x-axis values are all zero, so Flot is correctly plotting all the bars on top of one another.
您的 x 轴值都为零,因此 Flot 正确地绘制了所有条形图。
Thanks to DNS, the problem is the all my x-axis values are zero, so i changed my JSON in the following format,多亏了 DNS,问题是我所有的 x 轴值都为零,所以我按以下格式更改了 JSON,
[{"data":[[0,5202]],"label":"Over Time"},{"data":[[1,19620]],"label":"Shift Start"},{"data":[[2,82920]],"label":"Maintenance break"},{"data":[[3,240]],"label":"Lunch break"},{"data":[[4,75720]],"label":"BreakDown"},{"data":[[5,3060]],"label":"Break"},{"data":[[6,72840]],"label":"Tea break"},{"data":[[6,79260]],"label":"Power Failure"}]
Now i get my graph like this,现在我得到这样的图表,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.