对于flot js中的图形,x轴的时间没有正确显示

I'm plotting graph using flot js. Now date stored in the database is in this form.

2015-10-29 11:35:33

I convert it to miliseconds, pass to ajax to plot the graph and that graph ought to display date in x-axis not in miliseconds but in readable date.

This is how its shown presently, enter image description here

If you notice the x-axis, I believe its only showing the time as value for y are all for the same day, same hour but slightly difference in minutes.Please take a look at below table that shows the value (total_bv) and dates (as_of_date).

enter image description here

Problem is, date the date shown in x-axis. what does that 03:3, 03:38 and so forth about. I think its the time which doesn't converted to correct time zone?

Because in the PHP script where I get the data from database, I use timezone asia/kuala lumpur. If I don't use this timezone the time displayed in x-axis starts with 10:36, 10:38 and so forth.. SO can anyone tell me first how to show the correct Date & time in x-axis in readable format?

date_default_timezone_set("Asia/Kuala_Lumpur");
$acceptedUser = new search();
$sales = $acceptedUser->get_sales_graph();
$before = array();
foreach($sales as $k=>$v)
{
    $date = strtotime($v['as_of_date']) * 1000;
    array_push($before, array("datey" => $date, "bv" => $v['total_bv']));
}
echo json_encode($before);

1个回答



所以看起来你有两个问题:</ p>


  1. 日期转换 /数据库中的时间字符串到JavaScript毫秒时间戳,注意时区。</ li>
  2. 显示刻度值的某种日期/时间字符串。</ li>
    </ ol> \ n

    解决了这两个问题。 flot.js文档。</ p>

    首先,flot假定时间戳是UTC。 如果要更改它,可以通过将轴< timezone </ code>属性设置为 browser </ code>(根据用户的浏览器转换时间戳)来实现,或者可以使用时区。 JS。 然而,大多数开发人员只是假装他们正在使用的时间戳已经在正确的时区中(这基本上就是你正在做的并且已经注意到了)。</ p>

    其次,使用显式格式字符串 对于带有轴刻度的 timeformat </ code>属性。 该文档包含可替换格式说明符的完整列表。</ p>
    </ div>

展开原文

原文

So it seems you have two issues:

  1. The conversion of date/time strings from your database to JavaScript millisecond timestamps, paying attention to time zones.
  2. Displaying some kind of date/time string for your tick values.

Both of these are addressed by the flot.js documentation.

First of all, flot assumes that timestamps are UTC. If you want to change that, you can do so through setting the axis' timezone property to browser (converts timestamps according to the user's browser), or you can use timezone.js. However most devs just pretend that the timestamp they are using is already in the correct timezone anyway (which is essentially what you're doing and have noticed).

Second, use an explicit format string for the timeformat property with the axis ticks. The documentation has the full list of replaceable format specifiers.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问