Re: Uncaught Error: Invalid value in 0,0

113 views
Skip to first unread message

asgallant

unread,
Dec 26, 2012, 12:28:39 PM12/26/12
to google-visua...@googlegroups.com
The problem here is that the {v: value, f: 'formatted value'} syntax is not valid for use with the arrayToDataTable method (as documented here).  If you want to use that syntax, you will have to define your DataTable manually, and then use the #addRows method, like this:

var data new google.visualization.DataTable();
data.addColumn('number''Camera');
data.addColumn('number''Avg Rating');
data.addRows([
    [{v:6000f'Canon EOS-1Ds Mark III'}60],
    [{v:5000f'Canon EOS-1Ds Mark II'}50],
    [{v:4000f'Canon EOS-1D Mark IV'}40]
]);

On Tuesday, December 25, 2012 11:33:41 PM UTC-5, Reza Mirza wrote:

I'm having a really weird issue while trying to visualize this scatter plot using the google visualization API.

Basically, if I put the first data point as [0,0] everything will be fine, but if remove [0,0] as the first point, the chart won't produce. I checked the console and this is what I said:

"Uncaught SyntaxError: Unexpected token <
Uncaught Error: Invalid value in 0,0"

Why exactly does the first point need to be [0,0]?

<html>
  <head>
    <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 = google.visualization.arrayToDataTable([
          ['Camera','Avg Rating'],
          [ {v:6000, f: 'Canon EOS-1Ds Mark III'}, 60],
          [ {v:5000, f: 'Canon EOS-1Ds Mark II'}, 50],
          [ {v:4000, f: 'Canon EOS-1D Mark IV'}, 40]
        ]);

        var options = {
          title: 'Breakdown of Camera Models by Price, Photo Rating and Brand',
          hAxis: {title: 'Price (USD)', minValue: 0, maxValue: 7500},
          vAxis: {title: 'Avg Rating (at peak)', minValue: 0, maxValue: 55},
          legend: 'none'          
        };
        var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 1000px; height: 1000px;"></div>
  </body>
</html>

Manmohan Kaur

unread,
Oct 14, 2014, 3:36:59 AM10/14/14
to google-visua...@googlegroups.com
I have been reading this thread and looks like you may be able to help me. I am trying to connect my mysql database table to Google Visualizations 

I am attaching two files, one is the html file called map1.html
the json code is processed in example.php  It is saving the encoded file as Pie2.json which is being called by getData.php
 

Upon execution I get this error  Uncaught SyntaxError: Unexpected token .

Thank you
map1.html
example.php

Andrew Gallant

unread,
Oct 15, 2014, 9:23:52 PM10/15/14
to google-visua...@googlegroups.com
Your DataTable construction is not correct.  Try this:

<?php
    $con=mysqli_connect("localhost","root","","data_trafiek");
    $result = mysqli_query($con,"select date,vol_dl,vol_ul from per_uur");

    if ($result !== false) {
        $output = array(
            'cols' => array(
                array('type' => 'date', 'label' => 'Date'),
                array('type' => 'number', 'label' => 'MyValue1'),
                array('type' => 'number', 'label' => 'MyValue2')
            ),
            'rows' => array()
        );
        while ($row = mysqli_fetch_assoc($result)) {
            $DateTimeArray = $row["date"];
            $MYvalue1 = (int)round($row["vol_dl"]/100000);
            $MYvalue2 = (int)round($row["vol_ul"]/100000);

            $date = date('Y-m-d', strtotime($DateTimeArray));
            $dateArray = explode('-', $date);
            $year = $dateArray[0];
            $month = $dateArray[1] - 1; // adjust for javascript's 0-indexed months
            $day = $dateArray[2];

            // do you need the time?
            // if not, delete the time related code
            $time = date('H:i:s', strtotime($DateTimeArray));
            $timeArray = explode(':', $time);
            $hours = $timeArray[0];
            $minutes = $timeArray[1];
            $seconds = $timeArray[2];

            $output['rows'][] = array('c' => array(
                array('v' => "Date($year, $month, $day)"),
                array('v' => $MYvalue1),
                array('v' => $MYvalue2)
            ));
        }
        echo json_encode($output, JSON_NUMERIC_CHECK);
    }
?>
Reply all
Reply to author
Forward
0 new messages