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

[code]

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

$(function () {
$(document).ready(function() {
Highcharts.setOptions({
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>'+ this.series.name +'</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(),
                    i;

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

});


</body>
[/code]

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

Hi,

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

[php]

Using Highcharts with PHP and MySQL
[/php]

The above is how we call highcharts and display it

[php]<?php
$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”;
}

mysql_close($con);
?> [/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