-2

I want to get the data from the php variables into the pie chart as I tried to do it with $Utha and the value of $one in its position of the pie chart. How would this work with an example connecting from a database? How can I make multiple charts appear in the same page. For example more than one chart with different data each. Can these charts be centered.

<?php
$Utha = 'Utha';    
$Ilinois = 'Ilinoins';
$WD = 'Washington DC';
$Florida = 'Florida';
$California = 'California';

$one = 1;
$two = 2;
$three = 3;
$four = 4;
$five = 5;
?>
<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([
          ['Task', 'Hours per Day'],
          ['$Utha',     $one],
          ['$Ilinois',  $two],
          ['$Florida',  $three],
          ['$California', $four],
          ['$WD',    $five]
        ]);

        var options = {
          title: 'My Daily Activities',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="piechart_3d" style="width: 900px; height: 500px;"></div>
  </body>
</html>
learningbyexample
  • 1,527
  • 2
  • 21
  • 42

2 Answers2

0

You can create variable in javascript based on PHP variable, example :

var one = '<?php echo $one; ?>';

Hope this helps.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
0
var demo = "<?php echo $phpVar; ?>";
Krishna Gupta
  • 695
  • 4
  • 15