使用Highcharts制作的线形图显示Xaxis上的时间 [英] Display time on Xaxis with line chart make by Highcharts

查看:820
本文介绍了使用Highcharts制作的线形图显示Xaxis上的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a line chart with Highcharts and everything was fine but the X-axis. It's not displaying the right data which I have get from mysql. This is my chart right now but it is not what i expected. X-Axis row auto change all of my data to 01:[my minutes]:[my mins], example: my data is:2015-05-12 08:23:40 it auto convert to 01:23:40. i don't know why

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

我需要一个图表看起来像这样,但我不知道如何解决它,帮助我。

I need a chart look like this but I don't know how to fix it, help me please.

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


推荐答案

问题解决,这个代码和一切工作完美。

Problem solved, you just need to add this code and everything works perfectly.

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

这篇关于使用Highcharts制作的线形图显示Xaxis上的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆