score:1
First of all, you have some errors in your code.
- You have the
<body>
tag inside the<head>
tag. - The
$.ajax()
is expecting ajson
response, however your json data is incorrect.
Valid json data:
[
{
"name": "DEL",
"data": [96.65,96.71,96.37]
},
{
"name" : "MUM",
"data": [96.22,96.29,96.61]
},
{
"name": "KOL",
"data": [97.21,97.56,97.24]
},
{
"name": "CHN",
"data": [96.52,96.50,96.67]
}
]
Now, about the problem:
I'd suggest to follow this:
- Make a helper request function that returns the
$.ajax()
function.
Example:
function request() {
return $.ajax({
url: "https://gist.githubusercontent.com/dannyjhonston/0a573e0a882180d20df56357ac05345d/raw/541a5d3e17e686820c0476a630d490ff46fb47c2/successper.json",
type: "GET",
async: true,
dataType: "json"
});
}
- Call the request function in the
$(function(){});
block. By using.done()
in the request function, you can get the json data from the URL. In thedone()
function build the HighChart content.
Example:
$(function() {
request().done(function(point) {
options.series = point;
var chart = new Highcharts.Chart(options);
});
});
- Set the
load
function in theevent
object in the chart options. Then with the current json data response you can use theupdate()
series method.
update (Object options, [Boolean redraw]) Update the series with a new set of options. For a clean and precise handling of new options, all methods and elements from the series are removed, and it is initiated from scratch. Therefore, this method is more performance expensive than some other utility methods like setData or setVisible.
Parameters
- options: Boolean New options that will be merged into the series' existing options.
- redraw: Boolean Defaults to true. Whether to redraw the chart after the series is altered. If doing more operations on the chart, it is a good idea to set redraw to false and call chart.redraw() after.
Example:
events: {
load: function() {
var series = this.series[0]; // Get the current series.
setInterval(function() { // For every 5 seconds call the request function.
request().done(function(point) {
series.update(point); // Get the point (json data from the URL) and use the update(point) method.
console.log("Updated with this: ", point);
});
}, 5000);
}
}
Something like this:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>C2S Success %</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body class="theme-light">
<font color="WHITE">
<marquee behavior="scroll" direction="left" style="background:RED">Testing Etopup Dashboard </marquee>
</font>
<script type="text/javascript">
// (1)
function request() {
return $.ajax({
url: 'https://gist.githubusercontent.com/dannyjhonston/0a573e0a882180d20df56357ac05345d/raw/541a5d3e17e686820c0476a630d490ff46fb47c2/successper.json',
type: "GET",
async: true,
dataType: "json"
});
}
var options = {
chart: {
renderTo: "chart1",
type: "column",
height: 500,
width: 530,
events: { // (3)
load: function() {
var series0 = this.series[0];
var series1 = this.series[1];
var series2 = this.series[2];
setInterval(function() {
request().done(function(point) {
series0.update({
name: point[0].name,
data: point[0].data
});
series1.update({
name: point[1].name,
data: point[1].data
});
series2.update({
name: point[2].name,
data: point[2].data
});
});
}, 5000);
}
}
},
title: {
text: "Success %"
},
xAxis: {
categories: ["Today", "YesterDay", "D-7"],
title: {
text: "DAYs"
}
},
plotOptions: {
column: {
dataLabels: {
enabled: true
}
}
},
series: []
};
// (2)
$(function() {
request().done(function(point) {
options.series = point;
var chart = new Highcharts.Chart(options);
});
});
</script>
<div id="chart1" style="width: 300px; height: 200px;"></div>
</body>
</html>
Don't forget to change https://gist.githubusercontent.com/dannyjhonston/0a573e0a882180d20df56357ac05345d/raw/541a5d3e17e686820c0476a630d490ff46fb47c2/successper.json
by your successper.php
page.
Update:
As you have an array with 4 elements, change:
events: {
load: function() {
var series = this.series[0]; // Get the current series.
setInterval(function() { // For every 5 seconds call the request function.
request().done(function(point) {
series.update(point); // Get the point (json data from the URL) and use the update(point) method.
console.log("Updated with this: ", point);
});
}, 5000);
}
}
to this:
events: {
load: function() {
var series0 = this.series[0];
var series1 = this.series[1];
var series2 = this.series[2];
var series3 = this.series[3];
setInterval(function() { // For every 5 seconds call the request function.
request().done(function(point) {
series0.update({
name: point[0].name,
data: point[0].data
});
series1.update({
name: point[1].name,
data: point[1].data
});
series2.update({
name: point[2].name,
data: point[2].data
});
series3.update({
name: point[3].name,
data: point[3].data
});
});
}, 5000);
}
}
Update: The php code of the successper.php page from my demo site.
<?php
header("Access-Control-Allow-origin: *");
header("Content-Type: application/json");
header("Cache-Control: no-cache");
$min = 0;
$max = 100;
$array = array(array(name => "DEL", data => array(mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10)),
array(name => "MUM", data => array(mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10)),
array(name => "KOL", data => array(mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10)),
array(name => "CHN", data => array(mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10, mt_rand ($min*10, $max*10) / 10)));
echo json_encode($array);
flush();
?>
You can see the working example here.
Hope this helps.
Source: stackoverflow.com
Related Query
- high chart column chart dynamic update with ajax
- Ajax dynamic data with column bar chart
- knockoutJS dynamic chart with high charts
- High chart - Column Range Chart with Time range. How to get tooltip as Start and End time
- High charts queue chart updates after ajax with multiple charts in firefox
- how can we draw column chart with stacked column chart in a single high chart?
- How to Create a Stacked Column Chart with Dynamic Series in Highcharts
- Highcharts Multiple Series Dynamic Column Chart Update
- How to avoid blank candles showing 0, 0, 0, 0 in highstock candlestick chart on dynamic update with shift
- High chart problwm with multiple axes with dynamic data
- Highcharts - how to have a chart with dynamic height?
- How to show a column with the value Zero in Column chart in Highcharts?
- highcharts jquery dynamic change chart type column to bar
- Highcharts Column chart with drilldown, remove hyperlink like formatting from x-axis labels
- Need stacked column chart with multiple series
- Add dynamic data to line chart from mysql database with highcharts
- Highcharts Grouped Column Chart with Multiple Groups?
- Pagination in column chart with Previous, Next controls?
- Highcharts - update column graph with setData() not working
- How to use add series and update methods in the high chart wrapper for angular?
- AngularJS for Highcharts with dynamic ajax data
- Highcharts column + line combination chart with multiple series. Issue aligning line over the column
- Trying to update high chart data
- High charts: Can we reduce the distance between two bars in grouped column chart
- Highcharts multiple column chart with drilldown, correct formatting of drilldown axes
- How-to Dynamic update a chart via socket.io and slide chart view as a sliding window?
- How to Build a Column Chart in Highcharts with Data Entered Dynamically Within a CMS
- trying to dynamically update Highchart column chart but series undefined
- Highcharts - update chart using ajax
- Updating basic column high chart
More Query from same tag
- stacked bar chart with separate label
- Hightcharts - Not showing column datalabels when chart type is column
- Show TIME instead of DATE in Timeline Highcharts
- Calling Highcharts within a function
- Dynamic width for each column if value is 0 in highcharts
- How can I change the color of legend points?
- Highcharts plotlines label events
- Link table data with chart data Jquery
- Multiline Highchart based on Dates
- Loading libraries and additional modules with requirejs
- Server side chart .svg export with Highcharts and PhantomJS, error loading data from .csv file
- The HighCharts CSV export module went missing
- highchart column chart color for same month
- Highcharts combination chart from JSON data
- Pie chart slice - center of mass
- xAxis type: 'category' without stacking duplicate names?
- Highcharts capture selection
- Show only discontinuous points in Highcharts line graph
- how to split by hour in highcharts while using x-axis type date range
- Highcharts remove space before first bar and after last
- Highchart graph display on iPad going out of container
- How To Show All Data Labels For Datetime Axis In Highcharts
- Highcharts plotBands do not work with setExtremes function
- Highchart xAxis labels formatter not displaying returned value
- Using an array for data in highcharts
- Drill Down (Highcharts) not working in Angular 5
- highcharts - to show a no data picture in case nothing to render from mysql query
- Problematically highlight(hover) a serie ,highcharts
- HighCharts Y Axis scales aren't correct
- How to limit chart xAxis date range in HighCharts?