dongzi0602 2015-11-04 10:01
浏览 91

对于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条回答

  • dongluanban3536 2015-11-25 22:36
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现