Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Somebody can help me. I'm new in php and highcharts. I tried to populate my chart using mysql and php, but when I tried to run it, the chart didn't appear, I only sse a blank web page. And there's no error appeared.

Her's my codes (sorry for messy code):

<!DOCTYPE HTML>
 <html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Highcharts Example</title>

       <script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="../../js/highcharts.js"></script>
    <script src="../../js/modules/exporting.js"></script>

</head>

        <body>

    <?php
include "config.php";

$SQL1 =     "SELECT * FROM pos";

$result1 = mysql_query($SQL1);
$data1 = array();
while ($row = mysql_fetch_array($result1)) {
   $data1[] = $row['name'];
   $data2[] = $row['Qty'];

}
?>

<script type="text/javascript">
$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column',
            margin: [ 50, 50, 100, 80]
        },
        title: {
            text: 'List of POS'
        },
    credits: {
    enabled: false
    },
        xAxis: {
            categories: [<?php echo join($data1, "','"); ?>],
            labels: {
                rotation: -45,
                align: 'right',
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'No. of Ticket'
            }
        },
        legend: {
            enabled: false,
    layout: 'vertical',
                        backgroundColor: '#FFFFFF',
                        align: 'left',
                        verticalAlign: 'top',
                        x: 50,
                        y: 35,
                        floating: true,
                        shadow: true
        },
        tooltip: {
            pointFormat: '<b>{point.y:.1f} tickets</b>',
        },
     plotOptions: {
                            column: {
                                        pointPadding: 0.2,
                                        borderWidth: 0
                                    }
                        },
        series: [{
            name: 'Qty',
            data: ['<?php echo join($data2, "','"); ?>'],
    dataLabels: {
                enabled: true,
                rotation: -90,
                color: '#FFFFFF',
                align: 'right',
                x: 4,
                y: 10,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif',
                    textShadow: '0 0 3px black',

                }
            }
        }]
    });
});

    </script>

   <div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>

</body>
    </html>

And here's my config.php

 <?php
 $mysql_hostname = "localhost";
 $mysql_user = "root";
 $mysql_password = "";
 $mysql_database = "pos";
 $prefix = "";
 $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not  connect database");
 mysql_select_db($mysql_database, $bd) or die("Could not select database");

  ?>
share|improve this question
1  
If you view the source of the webpage your are trying to display this, does it show all the JavaScript correctly? That's an easy way to find out if you have a php problem or a JavaScript one –  Arian Dec 27 '13 at 2:29
    
How does your json look like? can show that what actually is being written? –  SPandya Dec 27 '13 at 7:03
    
I don't have json file, instead direct coding into mysql and php –  user3098728 Dec 27 '13 at 8:46
    
Take look at the similiar topic highcharts.com/docs/working-with-data/…. I advice to return json in your php file, and then load json by jquery. You will be ensured that all values are correct. –  Sebastian Bochan Dec 27 '13 at 10:12
add comment

2 Answers

up vote 1 down vote accepted

Blank pages usually mean syntax errors. You should switch error_reporting on.

The errors are in the use of your echo statements where you construct the json. The error is that you are missing semi colons in both the echo statements.

Replace <?php echo join($data1, ',') ?> with <?php echo join($data1, ','); ?>

Similarly for $data2:

Replace <?php echo join($data2, ',') ?> with <?php echo join($data2, ','); ?>

Another improvement you could make in the following block:

    <?php
include "config.php";

$SQL1 =     "SELECT * FROM pos";

$result1 = mysql_query($SQL1);
$data1 = array();
while ($row = mysql_fetch_array($result1)) {
   $data1[] = $row['name'];
}

$result2 = mysql_query($SQL1);
$data2 = array();
while ($row = mysql_fetch_array($result2)) {
   $data2[] = $row['Qty'];
}
?>

Instead of executing query twice to build two arrays, you could get rid of one of the queries and build both the arrays from the same query result:

<?php
include "config.php";

$SQL1 =     "SELECT * FROM pos";

$result1 = mysql_query($SQL1);

$data1 = array();
$data2 = array();

while ($row = mysql_fetch_array($result1)) {
   $data1[] = $row['name'];
   $data2[] = $row['Qty'];
}
?>

Note: The php mysql extension is deprecated as of PHP 5.5.0, you should be using either MySQLi or PDO_MySQL.

share|improve this answer
    
I already did what you said, but nothing change. And I encountered new error --- Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80 Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166 Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config\Container.php on line 111 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\otrs\chart\graphs\pos\index.php on line 22 –  user3098728 Dec 27 '13 at 2:50
    
That error tells me that either the connection to the database is not successful or the query failed. Can you post your Config.php? –  vee Dec 27 '13 at 2:54
    
Here's my config.php -- <?php $mysql_hostname = "localhost"; $mysql_user = "root"; $mysql_password = ""; $mysql_database = "pos"; $prefix = ""; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database"); mysql_select_db($mysql_database, $bd) or die("Could not select database"); ?> –  user3098728 Dec 27 '13 at 2:56
    
I put the config.php in the folder where my index.php place and the error was gone, but when I reload the webpage, I got a blank web page again –  user3098728 Dec 27 '13 at 3:01
    
Please update your question with the updated code you're using. –  vee Dec 27 '13 at 3:02
show 2 more comments

I think your supposed to have single quotes around this

categories: [<?php echo join($data1, ',') ?>],

Should be

categories: ['<?php echo join($data1, ',') ?>'],
share|improve this answer
    
Thanks, but I already tried that but nothing change –  user3098728 Dec 27 '13 at 2:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.