How do I get my data in my chart??

27 views
Skip to first unread message

Ro

unread,
May 23, 2012, 10:05:57 PM5/23/12
to Google Visualization API


How do I put variables instead of (v:20, f:'$20M") etc???????

from ['January',v:20, f:'$20M'] to ['January',variable1, variable2],

function drawVisualization(idTarget) {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number', 'Sales');
data.addRows([
['January',{v:20, f:'$20M'}],
['February',{v:31, f:'$31M'}],
['March',{v:61, f:'$61M'}],
['April',{v:26, f:'$26M'}],
['May',{v:10, f:'$10M'}]
]);
// Create and draw the visualization.
new google.visualization.PieChart(
document.getElementById(idTarget)).
draw(data, {is3D:true});
}

asgallant

unread,
May 24, 2012, 9:02:07 AM5/24/12
to google-visua...@googlegroups.com
This is what you would use:

['January', {v: variable1, f: variable2}]  

IL MOSTRO

unread,
May 24, 2012, 9:46:33 AM5/24/12
to google-visua...@googlegroups.com

Thanks i'll try it

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/Bo_SJnbBH5kJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

IL MOSTRO

unread,
May 24, 2012, 2:22:31 PM5/24/12
to google-visua...@googlegroups.com
hi this is ma code and it does not work
please help

<?php
$variable_php=1;

echo '<html>
  <head>
  
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
var varjs="'.$variable_php.'";
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          [\'Year\', \'Sales\', \'Expenses\'],
          [varjs,  v:varjs,      400],
          [\'2005\',  1170,      460],
          [\'2006\',  660,       1120],
          [\'2007\',  1030,      540]
        ]);

        var options = {
          title: \'Company Performance\',
          hAxis: {title: \'Year\', titleTextStyle: {color: \'red\'}}
        };

        var chart = new google.visualization.ColumnChart(document.getElementById(\'chart_div\'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>'
?>

asgallant

unread,
May 24, 2012, 2:43:12 PM5/24/12
to google-visua...@googlegroups.com
There are a few things you'll need to know to make this work:

1) The object {v: value, f: 'formatted value'} represents a single cell in the table, where the 'v' property is the value of the cell and the 'f' property is the string-formatted value of the cell (like {v: 5, f: '5 apples'}).  Most of the time, you don't need to use this syntax; using just the value works fine.

2) The line:

[varjs,  v:varjs,      400], 

will throw an error, because the syntax "v:varjs" only has meaning in an object, not an array.  You would need this instead:

[varjs, {v:varjs}, 400],
 
3) If you want more than one row of data, there are much easier ways to write this code that will save you a lot of time and effort

IL MOSTRO

unread,
May 24, 2012, 2:58:08 PM5/24/12
to google-visua...@googlegroups.com
thanks for the help, but it still does not work i have tried :

 [varjs,  {v:varjs},      400],

and

 [varjs,  {varjs},      400],



2012/5/24 IL MOSTRO <mostro....@gmail.com>

asgallant

unread,
May 24, 2012, 4:16:41 PM5/24/12
to google-visua...@googlegroups.com
You're putting the same data in both columns, and if you are still using the line:

var varjs="'.$variable_php.'";

then you are setting the variable as a string and putting it into a column that should have a number (the second column in the array).  If you had two variables it would look like this:

[varjs1, varjs2, 400], 
Reply all
Reply to author
Forward
0 new messages