Charting values collected in through PHP

8 views
Skip to first unread message

MatthewClay

unread,
Mar 15, 2018, 7:35:34 AM3/15/18
to Google Visualization API
Is it possible to show a graph where the values are gathered from PHP. I have the code below but it doesnt plot anything though i know the values are there

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>Month Detail</title>

  <link rel="stylesheet" href="../styles/dailykpi.css" media="all" />

  <?php include("monthdetail.php"); ?>

  <!--Load the AJAX API-->
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">

    // Load the Visualization API and the corechart package.
    google.charts.load('current', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
    google.charts.setOnLoadCallback(drawChart);

    // Callback that creates and populates a data table, instantiates the pie chart, passes in the data and draws it.
    function drawChart() {

      // Create the data table.
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Day Of The Month');
      data.addColumn('number', 'Amount Of Sales');
      data.addRows([
        ['Day 01', <?php $IntFormattedNum01d ?>],
        ['Day 02', <?php $IntFormattedNum02d ?>],
        ['Day 03', <?php $IntFormattedNum03d ?>],
        ['Day 04', <?php $IntFormattedNum04d ?>],
        ['Day 05', <?php $IntFormattedNum05d ?>],
        ['Day 06', <?php $IntFormattedNum06d ?>],
        ['Day 07', <?php $IntFormattedNum07d ?>],
        ['Day 08', <?php $IntFormattedNum08d ?>],
        ['Day 09', <?php $IntFormattedNum09d ?>],
        ['Day 10', <?php $IntFormattedNum10d ?>],
        ['Day 11', <?php $IntFormattedNum11d ?>],
        ['Day 12', <?php $IntFormattedNum12d ?>],
        ['Day 13', <?php $IntFormattedNum13d ?>],
        ['Day 14', <?php $IntFormattedNum14d ?>],
        ['Day 15', <?php $IntFormattedNum15d ?>],
        ['Day 16', <?php $IntFormattedNum16d ?>],
        ['Day 17', <?php $IntFormattedNum17d ?>],
        ['Day 18', <?php $IntFormattedNum18d ?>],
        ['Day 19', <?php $IntFormattedNum19d ?>],
        ['Day 20', <?php $IntFormattedNum20d ?>]
      ]);

      // Set chart options
      var options = {'title':'Daily Sales For Current Month',
                     'width':960,
                     'height':540};

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.BChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
  </script>

</head>

<body class="body">

    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>

</body>

</html>
Reply all
Reply to author
Forward
0 new messages