给定轴上的所有系列必须具有相同的数据类型 [英] All series on a given axis must be of the same data type

查看:129
本文介绍了给定轴上的所有系列必须具有相同的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我早期有格式化时间的问题,但现在有问题显示谷歌图表可视化的错误:给定轴上的所有系列必须是相同的数据类型。



这是目标,日期和时间: http://jsbin.com/ yaqew / 1 / edit



由于我已被通知,Google图表构造函数不会接受时间/日期字符串: https://developers.google.com/chart/interactive/docs/reference#dataparam



数据库:





PHP:

  <?php 

$ con = mysql_connect(localhost,root,)或die(无法连接数据库!!!!);
mysql_select_db(chart,$ con);

$ sth = mysql_query(SELECT * FROM googlechart);

$ rows = array();
//不需要标志
$ flag = true;
$ table = array();

$ table ['cols'] = array(

array('label'=>'Time','type'=>'datetime'),
数组('label'=>'Date','type'=>'datetime'),
数组('label'=>'PH','type'=& ''),
array('label'=>'temperature','type'=>'number'),
array('label'=>'Chlorine','type'= "'number'),
);

$ rows = array();

while($ r = mysql_fetch_assoc($ sth)){

//假定日期格式为yyyy-MM-dd
$ dateString = $ r ['Date'];
$ dateArray = explode(' - ',$ dateString);
$ year = $ dateArray [0];
$ month = $ dateArray [1] - 1; // subtract 1 to convert to javascript's 0-indexed months
$ day = $ dateArray [2];

echo $ dateString。< br>;

//假定时间格式为hh:mm:ss
$ timeString = $ r ['Time'];
$ timeArray = explode(':',$ timeString);
$ hours = $ timeArray [0];
$ minutes = $ timeArray [1];
$ seconds = $ timeArray [2];

echo $ timeString;

$ temp = array();
$ temp [] = array('v'=>Date($ year,$ month,$ day,$ hours,$ minutes,$ seconds));
$ temp [] = array('v'=>(string)$ r ['PH']);
$ temp [] = array('v'=>(string)$ r ['temperature']);
$ temp [] = array('v'=>(string)$ r ['Chlorine']);

$ rows [] = array('c'=> $ temp);

}

$ table ['rows'] = $ rows;
$ jsonTable = json_encode($ table);
/ * echo $ jsonTable; * /

?>

Html / Javascript:

 < script type =text / javascriptsrc =https://www.google.com/jsapi>< / script> 
< script type =text / javascript>
google.load(visualization,1,{packages:[corechart]});
google.setOnLoadCallback(drawChart);

函数drawChart(){
var data = new google.visualization.DataTable(<?= $ jsonTable?>);



var options = {
/ * width:900,height:900,* /
title:'Visualization',
curveType:'function',
legend:{position:'bottom'},
pointSize:12,
vAxis:{title:Values,titleTextStyle:{italic:false}},
hAxis:{title:Time,titleTextStyle:{italic:false}},
explorer:{
actions:['dragToZoom','rightClickToReset'],
轴:'vertical'
}


};

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data,options);


}


解决方案

p>您的列定义不正确:您只需要1列日期&时间,而不是两个:

  $ table ['cols'] = array(
array('label'=> ;'日期和时间','type'=>'datetime'),
数组('label'=>'PH','type'=>'number'),
array('label'=>'temperature','type'=>'number'),
array('label'=>'Chlorine','type'=>'number' b $ b);


I early had problems with formatting the time, but now having problem with showing the google chart visualiszation out of this error: All series on a given axis must be of the same data type.

This is the goal, with date and time: http://jsbin.com/yaqew/1/edit

As I have been notified the google chart constructor will not accept the time/date string: https://developers.google.com/chart/interactive/docs/reference#dataparam

Database:

PHP:

<?php

    $con=mysql_connect("localhost","root","") or die("Failed to connect with database!!!!");
    mysql_select_db("chart", $con);

    $sth = mysql_query("SELECT * FROM googlechart");

    $rows = array();
    //flag is not needed
    $flag = true;
    $table = array();

    $table['cols'] = array(

    array('label' => 'Time', 'type' => 'datetime'),
    array('label' => 'Date', 'type' => 'datetime'),
    array('label' => 'PH',      'type' => 'number'),
    array('label' => 'temperature','type' => 'number'), 
    array('label' => 'Chlorine','type' => 'number'),
    );

    $rows = array();

    while($r = mysql_fetch_assoc($sth)) {

    // assumes dates are in the format "yyyy-MM-dd"
    $dateString = $r['Date'];
    $dateArray = explode('-', $dateString);
    $year = $dateArray[0];
    $month = $dateArray[1] - 1; // subtract 1 to convert to javascript's 0-indexed months
    $day = $dateArray[2];

    echo $dateString."<br>";

    // assumes time is in the format "hh:mm:ss"
    $timeString = $r['Time'];
    $timeArray = explode(':', $timeString);
    $hours = $timeArray[0];
    $minutes = $timeArray[1];
    $seconds = $timeArray[2];

    echo $timeString;

    $temp = array();
    $temp[] = array('v' => "Date($year, $month, $day, $hours, $minutes, $seconds)"); 
    $temp[] = array('v' => (string) $r['PH']);
    $temp[] = array('v' => (string) $r['temperature']);
    $temp[] = array('v' => (string) $r['Chlorine']);

    $rows[] = array('c' => $temp);

    }

    $table['rows'] = $rows;
    $jsonTable = json_encode($table);
    /* echo $jsonTable; */  

?>

Html/Javascript:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = new google.visualization.DataTable(<?=$jsonTable?>);



        var options = {
        /*width: 900, height: 900, */
          title: 'Visualization',
          curveType: 'function', 
           legend: { position: 'bottom' },
           pointSize: 12,
        vAxis: {title: "Values", titleTextStyle: {italic: false}},
        hAxis: {title: "Time", titleTextStyle: {italic: false}},
        explorer: { 
                actions: ['dragToZoom', 'rightClickToReset'], 
                axis: 'vertical'
            }


        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);


      }

解决方案

Your column definitions are not correct: you want only 1 column for date & time, not two:

$table['cols'] = array(
    array('label' => 'Date & Time', 'type' => 'datetime'),
    array('label' => 'PH', 'type' => 'number'),
    array('label' => 'temperature','type' => 'number'), 
    array('label' => 'Chlorine','type' => 'number')
);

这篇关于给定轴上的所有系列必须具有相同的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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