Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript">
- google.load('current', {'packages':['corechart']});
- google.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = google.visualization.arrayToDataTable([
- ['Name', 'RunDate', 'Runs', 'Fails'],
- <?php
- $dbName = "my_test";
- $config = parse_ini_file("myconfig.ini",true);
- $dbUser = $config["DB"]["db_user"];
- $dbServer = $config["DB"]["db_ip"];
- $dbPassword = $config["DB"]["db_pass"];
- $con = mysql_connect($dbServer, $dbUser, $dbPassword);
- if (!$con) {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db($database, $con);
- $sql = mysql_query("select * from GraphTest");
- $output = array();
- while($row = mysql_fetch_array($sql)) {
- // create a temp array to hold the data
- $temp = array();
- // add the data
- $temp[] = '"' . $row['Name'] . '"';
- $temp[] = '"' . $row['RunDate'] . '"';
- $temp[] = (int) $row['Runs'];
- $temp[] = (int) $row['Fails'];
- // implode the temp array into a comma-separated list and add to the output array
- $output[] = '[' . implode(', ', $temp) . ']';
- }
- // implode the output into a comma-newline separated list and echo
- echo implode(",n", $output);
- mysql_close($con);
- ?>
- ]);
- // parse the data table for a list of locations
- var locations = google.visualization.data.group(data, [0], []);
- // build an array of data column definitions
- var columns = [1];
- for (var i = 0; i < locations.getNumberOfRows(); i++) {
- var loc = locations.getValue(i, 0);
- columns.push({
- label: loc,
- type: 'number',
- calc: function (dt, row) {
- // include data in this column only if the location matches
- return (dt.getValue(row, 0) == loc) ? dt.getValue(row, 2) : null;
- }
- });
- }
- // create a DataView based on the DataTable to get the correct snapshot of the data for the chart
- var view = new google.visualization.DataView(data);
- // set the columns in the view to the columns we constructed above
- view.setColumns(columns);
- var options = {
- title: 'data test',
- curveType: 'function'
- };
- var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
- // draw the chart using the DataView instead of the DataTable
- chart.draw(view, options);
- }
- </script>
- </head>
- <body>
- <h1> <?=var_dump($output)?> </h1> <!-- prints Array(0) {} -->
- <div id="chart_div" style="width: 900px; height: 500px;"></div>
- </body>
- </html>
- Not enough columns given to draw the requested chart.×
Add Comment
Please, Sign In to add comment