How to parse data into data table using google visualization

I’m using java script getting issues with data parsing into data table.2.php (1.1 KB)

value of ak is array(
[0] => SIS-L5-outside_rm_5019
[1] => SIS-L5-outside-rm5012
[2] => SIS-L5-Corridor
[3] => SIS-L1-Near-Lift
[4] => SIS-L1-Lobby(Near-Entrance)
[5] => SIS-L1-Subway-105
[6] => SIS-B1-GamesRm
[7] => SIS-B1-SMUSA
[8] => SIS-B1-Corridor
[9] => SIS-B1-Outside-C4SR
[10] => SIS-B1-Lounge
[11] => SIS-B1-Lift5

and kd is
[0] => 1275.5506213988
[1] => 1290.7307725817
[2] => 1302.7705921255
[3] => 1243.0720371736
[4] => 1162.4230535716
[5] => 1149.6843381107
[6] => 1162.1262680995
[7] => 1069.3115580757
[8] => 1058.0760042459
[9] => 1007.656771716
[10] => 1029.8077281041
[11] => 1010.4399878141

I want to create histogram using both values Xaxis should be ak value and Y axis should be kd values getting error when creating datatables error(2.php:11 Uncaught SyntaxError: Unexpected number)

Encode first the data via json encode to use them in javascript Example:
$post_data = json_encode($post_data);
If you do this then post the new $post_data format to see how it we manipulate them to using in js

Thanks Liontas!
I did that here you can see i think i have issues in parsing at var data = new google.visualization.DataTable(pausecontent);
Here is my code.2.php (1.1 KB)

Can you post a sample of the json data that you have?


<!DOCTYPE html>
        <title>Histogram Sitepoint</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src=""></script>

    var pausecontent =[['Dinosaur', 'Length']];            
    var dataObj=[{"SIS-L5-outside_rm_5019":1275.5506213987728,
       for(var k in dataObj[0]){
      google.charts.load("current", {packages:["corechart"]});
      function drawChart() {
        var data = google.visualization.arrayToDataTable(pausecontent);               

        var options = {
          title: 'Lengths of dinosaurs, in meters',
          legend: { position: 'none' }

        var chart = new google.visualization.Histogram(document.getElementById('chart_div'));
        chart.draw(data, options);
   <div id="chart_div" style="width: 900px; height: 500px;"></div>


Thanks Liontas,

it is working properly but if i want to print x axis values on Y and Y axis values on x but i’m not able to do so. Can u suggest me

Invert the push [dataObj[0][k].to string(),k]

tried that not getting proper values, It is taking random values.

Set orientation to vertical as you see in the following images:

oops Ok Thanks,

one more thing is that it is taking random values 0,1,2,3,4 for x axis but i have some values that are not numbers, So i changed x axis values(SIS-L5-outside_rm_5019) with index values so that it can be single value plot but i’m not able to parse it. What i’m trying is here i have values on y are 12 so i’m taking on x axis 1-12numbers.

Are you sure that the Histogram is the graph for your case?As i read at google

A histogram is a chart that groups numeric data into bins, displaying the bins as segmented columns. They’re used to depict the distribution of a dataset: how often values fall into ranges.

Yes I’m sure. I’m trying to create this one. X axis will be 1-12 nos and Y axis will be the values i’m giving above.

In above mention plot the problem is ti is plotting all values at 0(x axis) instead of that it should plot like that

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.