question on dynamic update chart problem.

lately im been doing some chart which require me to do some dynamic update purpose.

after i been searching in the web i found some chart which call highchart dynamic

the code i found is at below


Highcharts Example
	<script type="text/javascript" src=""></script>
	<script type="text/javascript">

$(function () {
$(document).ready(function() {
global: {
useUTC: false

    var chart;
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'spline',
            marginRight: 10,
            events: {
                load: function() {

                    // set up the updating of the chart each second
                    var series = this.series[0];
                    setInterval(function() {
                        var x = (new Date()).getTime(), // current time
                            y = Math.random();
                        series.addPoint([x, y], true, true);
                    }, 1000);
        title: {
            text: 'Live random data'
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150
        yAxis: {
            title: {
                text: 'Value'
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
        tooltip: {
            formatter: function() {
                    return '<b>'+ +'</b><br/>'+
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
                    Highcharts.numberFormat(this.y, 2);
        legend: {
            enabled: false
        exporting: {
            enabled: false
        series: [{
            name: 'Random data',
            data: (function() {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),

                for (i = -19; i <= 0; i++) {
                        x: time + i * 1000,
                        y: Math.random()
                return data;



it create random data and is great for me to use.

but im new to this. so i wanted to chart get the data from my mysql database. i would like to know how am i doing it?? i hv my connection file.

i do not know where should i put it …

Please advice …

Thanks and happy new year


after i been searching for the highcharts, i hv been link to this tutorial which lead me to a sample for using highcharts with mysql data dyanamic inputs.

here is my sample code usage


Using Highcharts with PHP and MySQL

The above is how we call highcharts and display it

$con = mysql_connect(“localhost”,“root”,"");

if (!$con) {
die('Could not connect: ’ . mysql_error());

mysql_select_db(“highcharts_php”, $con);

$result = mysql_query(“SELECT * FROM highcharts_php”);

while($row = mysql_fetch_array($result)) {
echo $row[‘timespan’] . “\t” . $row[‘sellprice’]. “\n”;

?> [/php]

this is how i get my x axis data.

there here is my another question.

i been wondering the data is display for the datetime is using highcharts interval time which is belongs to y axis. how am i able to get the time from mysql data???

Sponsor our Newsletter | Privacy Policy | Terms of Service