dapcigar Posted April 16, 2015 Share Posted April 16, 2015 Hello , Am trying to display the data for the current year by department. i was able to populate the spent but could not display the budget. please what am i doing wrong <?php $date = $_POST['Date']; $dept = $_POST["department"]; //$date = '25/05/2010'; $date = str_replace('/', '-', $date); $new_date = date('Y-m-d', strtotime($date)); //echo $new_date; include('mysql_connect.php'); $year = date('Y'); // Settings for the graph include "libchart/classes/libchart.php"; /* $chart = new VerticalBarChart(600, 520); $chart = new VerticalBarChart(); $dataSet = new XYDataSet(); $query1 = mysql_query ("SELECT department , SUM(amount) as amt FROM requisition WHERE date = '$new_date' GROUP BY department ") or die(mysql_error()); while($row = mysql_fetch_array($query1)) { $dataSet->addPoint(new Point($row['department'], $row['amt'])); } $chart->setDataSet($dataSet); $chart->setTitle("Report By Month"); $chart->render("generated/date.png"); */ // header("Location: view_date.php"); //header ('lcoation : '); ?> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="highcharts.js"></script> <?php $q = "select sum(amount) 'amount', sum(actual) 'actual',department from transaction_log where Year(date)='$year' GROUP BY department "; $query1 = mysql_query ($q) or die(mysql_error()); // echo $q; // $values = array(); // $months = array("January","February","March","April","May","June","July","August","September","October","November","December"); while($row = mysql_fetch_assoc($query1)) { $categories[] = $row["department"]; // $budgets[$row["category"]] = $row["amount"]; $budgets[] = $row["amount"]; // $actuals[$row["category"]] = $row["actual"]; $actuals[] = $row["actual"]; //$values[] = $row; //$serie1->addPoint(new Point($row['department'], $row['amount'])); //$serie2->addPoint(new Point($row['department'], $row['actual'])); } $cats = json_encode($categories); $series = array(); $o = new stdClass(); $o->name = 'Spent'; $o->data = $actuals; $series[] = $o; $o = new stdClass(); $o->name = 'Amount'; $o->data = $amounts; $series[] = $o; $json = json_encode($series); ?> <div align="left"><img src="img/top.png" width="200" height="59" /> </div> <div id="container"></div> <script type="text/javascript"> $(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: 'Report For Jan - Mar 2015' }, subtitle: { text: '' }, xAxis: { categories:<?php echo $cats; ?>, labels: { rotation: -25, } }, yAxis: { min: 0, title: { text: '' } }, tooltip: { headerFormat: '<span style="font-size:10px">{point.key}</span><table>', pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>', footerFormat: '</table>', shared: true, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0, dataLabels: { enabled: true }, } }, series:<?php echo preg_replace("/\"([0-9]*?\.[0-9]*?)\"/","$1",$json); ?> }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/295609-high-chart-display/ Share on other sites More sharing options...
gizmola Posted April 16, 2015 Share Posted April 16, 2015 Hi let me suggest something that will help people. Utilize jsfiddle and get your graph up there. When you have your jsfiddle working you can publish it, and that way people can determine if it's a javascript or data issue. Here's an example of something I did a while back using Highstock (a specialized Highcharts variant) https://jsfiddle.net/gizmola/6wfaW/4/ In order to do this, you'll want to pull out the data seperately and add it as a constant into your code, so you would need to write a quick script that just pulls out the data and stores it as a string. Then you can copy that string into your jsfiddle. My example One obvious thing that jumps out is -- I have no idea why you are doing this: series:<?php echo preg_replace("/\"([0-9]*?\.[0-9]*?)\"/","$1",$json); Javascript is inherently able to utilize json, which is one of the reasons it is used frequently to pass data to javascript functions. You should simply be outputting the json into the series, not munging it for whatever reason. Quote Link to comment https://forums.phpfreaks.com/topic/295609-high-chart-display/#findComment-1509178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.