Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- // Load the Visualization API and the piechart package.
- google.charts.load('current', {'packages':['corechart']});
- // Set a callback to run when the Google Visualization API is loaded.
- google.charts.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = new google.visualization.DataTable();
- data.addColumn('Date', 'X');
- <?php
- /*
- $query = ($db->query("SELECT * FROM cubeprice.cubeprice WHERE CubeID = '$id'"));
- if (!$query->num_rows == 0) //if data exists
- {
- while($row = $query->fetch_assoc()) //while a row still exists
- {
- array_push($graphData, array($row["Price"], $row["ShopID"], $row["Date"])); //push ShopID and URL to array
- }
- }
- */
- foreach ($price as $key => $values)
- {
- echo "data.addColumn('number', '" . $values[3] . "');\n";
- }
- $graphData = array(); //array to store cube data
- $query = ($db->query("SELECT Price, MIN(Date) FROM CubePrice WHERE ShopID = 1 and CubeId = '$id'")); //get oldest price for certain cube & shop
- $row = $query->fetch_assoc();
- $begin = new DateTime($row["MIN(Date)"]);
- $end = new DateTime('now');
- $interval = DateInterval::createFromDateString('1 day');
- $period = new DatePeriod($begin, $interval, $end);
- foreach ($period as $dateKey => $dt)
- {
- $tempDate = $dt->format("Y, m, d)");
- $JSONDate = "new Date(" . $tempDate;
- $MYSQLDate = $dt->format("Y-m-d");
- $graphData[$dateKey][0] = $JSONDate;
- $tempArray = array();
- foreach($price as $priceKey => $values)
- {
- $queryString = "SELECT * FROM CubePrice.cubeprice WHERE (Date = '$MYSQLDate' and CubeID = '$id' and ShopID = '$values[0]');";
- if($query = $db->query($queryString))
- {
- $row = $query->fetch_assoc();
- array_push($tempArray, floatval($row["Price"]));
- }
- }
- array_push($graphData, $tempArray);
- }
- $json = json_encode($graphData);
- ?>
- data.addRows(
- <?php
- echo $json;
- ?>
- );
- var options = {
- title: 'Company Performance',
- curveType: 'function',
- legend: { position: 'bottom' }
- }
- // Instantiate and draw our chart, passing in some options.
- var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
- chart.draw(data, options);
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment