# question on dynamic update chart problem.

**URL:** <https://www.phphelp.com/t/question-on-dynamic-update-chart-problem/19255>\
**Category:** General PHP Help\
**Created:** [January 2, 2013, 4:35am UTC](https://www.phphelp.com/t/question-on-dynamic-update-chart-problem/19255 "2013-01-02T04:35:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elvatra](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@elvatra](https://www.phphelp.com/u/elvatra)\
**Post date:** [January 2, 2013, 4:35am UTC](https://www.phphelp.com/t/question-on-dynamic-update-chart-problem/19255/1 "2013-01-02T04:35:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![elvatra](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@elvatra](https://www.phphelp.com/u/elvatra)\
**Post date:** [January 8, 2013, 2:29am UTC](https://www.phphelp.com/t/question-on-dynamic-update-chart-problem/19255/2 "2013-01-08T02:29:17Z")

</div>

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???
