0

Is there any possibility to generate Google pie chart on my project? This code display a sum of cells from different id (single id for every year).

<dl>
    <dt>2014:</dt>
    <dd id="total2014"></dd>
</dl>
<dl>
    <dt>2013:</dt>
    <dd id="total2013"></dd>
</dl>
<dl>
    <dt>2012:</dt>
    <dd id="total2012"></dd>
</dl>

The content of id total2014 is still changing, so the best way would be, to generate the pie chart dynamical. I tried with <?php echo '<span id="total2014"></span>' ?> But it doesn't work, the chart disappear. Here's my code:

<script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Liters'],
          ['2014',    410], //Here I tried with <?php echo '<span id="total2014"></span>' ?>
          ['2013',      565],
          ['2012',  277]
        ]);

 var options = {
          title: 'Warki na przestrzeni lat',
        pieSliceText: 'value'
        };


        var chart = new google.visualization.PieChart(document.getElementById('piechart'));
        chart.draw(data, options);
      }
    </script>
 <div id="piechart" style="width: 700px; height: 500px; background-color:none;"></div>
pobliska
  • 237
  • 1
  • 4
  • 13
  • 1
    try this http://stackoverflow.com/questions/9888920/how-to-add-two-google-charts-on-the-one-page/18333105#18333105 – Pankaj Garg May 14 '14 at 19:36
  • If I understand correctly, you want to put the contents of `` into your DataTable and draw a PieChart with that. Are the contents of the span going to change while the page is open, or are they set at the time of page load? – asgallant May 14 '14 at 20:12
  • The span content is only loaded during loading the content of page from meta content (Wordpress). When the page is open nothing more is loaded. – pobliska May 14 '14 at 20:38

0 Answers0