Jump to content

High Chart Display


dapcigar

Recommended Posts

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>














Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.