【问题标题】:Display time on Xaxis with line chart make by Highcharts使用 Highcharts 制作的折线图在 Xaxis 上显示时间
【发布时间】:2015-07-24 08:32:08
【问题描述】:

我正在使用 Highcharts 制作折线图,除了 X 轴外,一切都很好。它没有显示我从 mysql 获得的正确数据。这是我现在的图表,但这不是我所期望的。 X 轴行自动将我的所有数据更改为 01:[my minutes]:[my mins],例如:我的数据是:2015-05-12 08:23:40 它自动转换为 01:23:40。我不知道为什么

http://imgur.com/YSC7vTl,Y4jYQ8q#0

我需要一个这样的图表,但我不知道如何修复它,请帮助我。

http://imgur.com/YSC7vTl,Y4jYQ8q#1

我的代码如下:

<?php 

     $query = "select distinct idchip from datatable ";
     $result = mysql_query( $query );
     $rows = array();
     $count = 0;

     while( $row = mysql_fetch_array( $result ) ) {

         $table = array();

         $query2 = "select datetime,temperature from datatable where idchip=".$row['idchip'].' group by datetime ';
         $query3 = "select datetime from datatable where idchip=".$row['idchip'].' group by datetime ASC';
         $timeresult = mysql_query($query3);

            while($datatime  = mysql_fetch_array($timeresult))
            {
                $newtime .= $datatime['0'].',';


                $newcates .= "'".$datatime['0']."',";
            } 

            $total= explode(",", $newtime);
            array_pop($total);
            $count = 0; 

            $dataresult = mysql_query($query2);
            while($datarow = mysql_fetch_array($dataresult))
            {

                $data = '';
                //$datatimes = '';

                $datatimes .= $datarow['0'].',';

                //$stringtime .= $datatimes;


            /*  $timetotal = explode(",",$datatimes);

                array_pop($timetotal);
                echo count($total).' |'; */

                //echo count($timetotal).' |';
                //echo $timetotal[$count]." |";
                //$data .= "[moment('".$datarow['0']."').valueOf(),".(integer)$datarow['1']."],";
                $data .= "[moment('".$datarow['0']."').valueOf(),".(integer)$datarow['1']."],";
                $stringdata .= $data;

                }

        $newstring = $stringdata ;
        //$total = '';
        //$newtime = '';
        $stringdata = '';
        $stringtime = '';

        //$stringcates = '';
        //echo $newstring;


        $namedata = "{name:'Chip ".$row["idchip"]."',data:[$newstring],type: 'spline'},";
        $getall .= $namedata;

     }

     $serries = 'series: [ '.$getall.' ]';



?>

这是我的 XAxis

xAxis: {

            type: 'datetime',
            datetime:[<?=$newcates?>],
            minTickInterval: moment.duration(1, 'month').asMinutes()
        },

这是我的数据库看起来像:

                id  idchip  datetime       signal temperature
Edit    Delete  1   5   2015-05-12 08:24:40     +   29
Edit    Delete  12  5   2015-05-12 08:23:40     +   031
Edit    Delete  3   6   2015-05-12 08:27:55     +   29
Edit    Delete  4   7   2015-05-12 08:26:01     +   50
Edit    Delete  5   5   2015-05-12 08:25:12     +   28
Edit    Delete  6   6   2015-05-12 08:28:32     +   29
Edit    Delete  7   6   2015-05-12 08:24:42     +   30
Edit    Delete  8   5   2015-05-12 08:27:58     +   29
Edit    Delete  9   5   2015-05-12 08:26:02     +   31
Edit    Delete  10  5   2015-05-12 08:26:13     +   29
Edit    Delete  11  5   2015-05-12 08:26:53     +   32

【问题讨论】:

  • @jlbriggs 添加了 global:{useUTC:false} 但没有任何改变:(
  • 您能否附上为series 生成的数据?我的意思是您的 PHP 在 Javascript 中为图表系列生成的内容。
  • @PawełFus 这是从我的数据库生成的序列:系列:[ {name:'Chip 5',data:[[moment('2015-05-12 08:23:40').valueOf (),31],[moment('2015-05-12 08:24:40').valueOf(),29],[moment('2015-05-12 08:25:12').valueOf() ,28],[moment('2015-05-12 08:26:02').valueOf(),31],[moment('2015-05-12 08:26:13').valueOf(),29 ],[moment('2015-05-12 08:26:53').valueOf(),32], ]
  • @PawełFus 请帮帮我:(。stackoverflow.com/questions/30233041/…

标签: javascript php mysql charts highcharts


【解决方案1】:

问题解决了,你只需要添加这段代码就可以了。

$(function() {
    Highcharts.setOptions({
         global: { 
        useUTC: false
    }
    });
});

【讨论】:

  • 别忘了接受你的回答! :) 工作演示:jsfiddle.net/r42jg/720
  • @PawełFus 谢谢pawel,19 小时后我会接受的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多