Jump to content

HELP! Highchart not displaying


dapcigar

Recommended Posts

Hello all,

 

 Am trying to display records from mysql using HIghchart but for some reasons, it is not bringing out any output, please help me look into my codes.

 

:::::::::::::::::::::::::::::::::::::data1.php ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

<?php
include('mysql_connect.php');
$dept = $_POST['department'];
//include('mysql_connect.php');
$stat = 'paid';


$result =  mysql_query ("select category, amount, actual from budget where department = '$dept' GROUP BY category  ") or die(mysql_error());

$category = array();
$category['name'] = 'category';

$series1 = array();
$series1['name'] = 'actual';

$series2 = array();
$series2['name'] = 'amount';

//$series3 = array();
//$series3['name'] = 'Highcharts';


while($r = mysql_fetch_array($query)) {
    $category['data1'][] = $r['category'];
    $series1['data1'][] = $r['actual'];
    $series2['data1'][] = $r['amount'];
  //  $series3['data'][] = $r['highcharts'];   
}

$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
//array_push($result,$series3);


print json_encode($result, JSON_NUMERIC_CHECK);
header("Location: view_dept.php");
mysql_close($con);

?>

:::::::::::::::::::::::::::::::::::::::: view_dept.php :::::::::::::::::::::::::::::::::

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
            var options = {
                chart: {
                    renderTo: 'container',
                    type: 'column',
                    marginRight: 130,
                    marginBottom: 25
                },
                title: {
                    text: 'Chart for Department',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    categories: []
                },
                yAxis: {
                    title: {
                        text: 'Amount'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    formatter: function() {
                            return '<b>'+ this.series.name +'</b><br/>'+
                            this.x +': '+ this.y;
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 0
                },
                series: []
            }
            
            $.getJSON("data1.php", function(json) {
                options.xAxis.categories = json[0]['data1'];
                options.series[0] = json[1];
                options.series[1] = json[2];
                //options.series[2] = json[3];
                chart = new Highcharts.Chart(options);
            });
        });
        </script>
        <script src="http://code.highcharts.com/highcharts.js"></script>
        <script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
 <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>

thanks in advance

Edited by Maq
Link to comment
Share on other sites

Based on a cursory look, the two scripts don't appear to be connected. It looks like you're trying to read in the database information in data1.php, then just redirecting to the script which displays the chart. Unfortunately, all the work done in the first script is lost when the redirect happens.

 

If you're trying to use the database information in the chart, you'll need to merge the scripts.

Link to comment
Share on other sites

Try removing the header("Location: view_dept.php") line from data1.php.

 

You can close the database connection and then use exit(); to halt script processing. As it stands, by the way, your connection is closed by the page refresh and not the explicit close command. Also, you'll want to start using PDO or mysqli_ - the mysql_ functions have been deprecated for quite some time and are scheduled to be removed in the near-ish future.

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.