Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysqli =mysqli_connect('localhost', 'dunham_scrubgras', 'scrub123', 'dunham_scrubgrass');
- if (mysqli_connect_errno()) {
- echo "Failed to connect to MySQL: ".mysqli_connect_error();
- }
- $sql = mysqli_query($mysqli, 'SELECT Output, DA_Price, RT_PRICE, Margin FROM scrubgrass');
- if (!$sql) {
- die("Error running $sql: " . mysql_error());
- }
- $results = array();
- while($row = mysqli_fetch_assoc($sql))
- {
- $results[] = array(
- 'Output' => $row['Output'],
- 'DA_Price' => $row['DA_Price'],
- 'RT_PRICE' => $row['RT_PRICE'],
- 'Margin' => $row['Margin']
- );
- }
- $json = json_encode($results, JSON_PRETTY_PRINT);
- //echo $json;
- ?>
- <html>
- <head>
- <title>Graphs</title>
- <!-- Load jQuery -->
- <script language="javascript" type="text/javascript"
- src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
- </script>
- <!-- Load Google JSAPI -->
- <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 jsonData = $.ajax({
- url: "php/tracker.php",
- dataType: "json",
- async: false
- }).responseText;
- var obj = window.JSON.stringify(jsonData);
- var data = google.visualization.arrayToDataTable(obj);
- var options = {
- title: 'graph'
- };
- var chart = new google.visualization.LineChart(
- document.getElementById('chart_div'));
- chart.draw(data, options);
- }
- </script>
- </head>
- <body>
- <div id="chart_div" style="width: 900px; height: 500px;">
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement