The answer is not so straight forward. To put it simple, you need ajax request to grab data from the server.
Here are the step in details
You need to create php, that returns json
<?php $return_arr = array(); $fetch = mysql_query("SELECT * FROM tbl_graph"); while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) { $row_array[] = $row['value']; array_push($return_arr,$row_array); } echo json_encode($return_arr); // This will return [4,5,6,7] in json ?>
Update your script to grab data from php
$(function () { var options = { chart: { renderTo: 'container' }, subtitle: { text: 'Subtitle' }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], tickInterval: 4 }, /*** The following Values are needed to be fetched from DB which are now static */ series: [{ data: [89.9, 21.5, 16.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }] }, chart = new Highcharts.Chart(options); $('#redraw').click(function() { // whenever you click redraw, it will grab json from php file above $.getJSON('http://yourpath.com/test.php', function (csv) { chart.series[0].setData(csv,true);//then set data and return csv } });
});
I haven't tested the code. Probably you need to figure it out if there is any syntax error. but hopefully you get sort of idea how to get json from php