score:0
Accepted answer
problem solved.
this is the code i added:
events: {
load: function requestdata() {
$.ajax({
url: 'live.php',
success: function(points) {
var series = chart.series,
shift;
$.each(series, function(i, s) {
shift = s.data.length > 1;
s.addpoint(points[i], true, true);
});
settimeout(requestdata, 1000);
chart.redraw();
},
cache: false
});
}
}
now i have historical data from my db and it adds new data point every time there's a new entry in de db without the need to refresh the page.
here is is my live.php code:
<?php
header("content-type: text/json");
$dbhost = 'localhost';
$dbname = 'highchart';
$dbuser = '*******';
$dbpass = '*******';
try{
$dbcon = new pdo("mysql:host={$dbhost};dbname={$dbname}",$dbuser,$dbpass);
$dbcon->setattribute(pdo::attr_errmode, pdo::errmode_exception);
}catch(pdoexception $ex){
die($ex->getmessage());
}
$stmt=$dbcon->prepare("select * from trafico");
$stmt->execute();
$json = [];
while($row=$stmt->fetch(pdo::fetch_assoc)){
extract($row);
}
$json[]= [strtotime($time_1m)*1000, (int)$tx];
$json[]= [strtotime($time_1m)*1000, (int)$rx];
echo json_encode($json);
?>
this is the output from live.php:
[[1522869181000,872],[1522869181000,54]]
and this is how the code looks now
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
var chart;
$(document).ready(function() {
highcharts.setoptions({
time: {
timezoneoffset: 3 * 60
}
});
var options = {
chart: {
renderto: 'container',
type: 'area',
zoomtype: 'x',
events: {
load: function requestdata() {
$.ajax({
url: 'live.php',
success: function(points) {
var series = chart.series,
shift;
$.each(series, function(i, s) {
shift = s.data.length > 1;
s.addpoint(points[i], true, true);
});
settimeout(requestdata, 1000);
chart.redraw();
},
cache: false
});
}
}
},
title: {
},
xaxis: {
type: 'datetime'
},
yaxis: {
},
series: [{
name: 'download',
data: []
}, {
name: 'upload',
data: []
}]
};
$.getjson('data.php', function(json) {
data1 = [];
data2 = [];
$.each(json, function(key,value) {
data1.push([value[0], value[1]]);
data2.push([value[0], value[2]]);
});
options.series[0].data = data1;
options.series[1].data = data2;
chart = new highcharts.stockchart(options);
});
});
</script>
<body>
<div id="container" style="min-width: 400px; height: 800px; margin: 0 auto"></div>
</body>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
Source: stackoverflow.com
Related Query
- How to display historical data and live data from database using Highcharts
- How to hardcode chart data in my Model then have my Controller pull it from there to display it. Using Highcharts
- How to use axios to fetch data from servlet and then crossfilter it and display via highcharts
- How to get data from multiple tables of MySQL DB and manuplate it using PHP to display graphs?
- Highcharts Highstock How to Plot OHLC and Line Charts from One Set of Embedded CSV Data Using Series Map Tools?
- How to scrape data from Highcharts charts using selenium and python?
- How to query data from database using highcharts in Codeigniter?
- Highcharts, influxdb and nodejs, how to display data of influxdb in highcharts using influxdb-nodejs?
- How to make multiple Y-axis with incoming series of data from database using Highcharts
- how to display Highcharts from database in C# .Net
- Fetch data from firebase firestore and plot histogram using highcharts when cardview clicked - android
- How To Get Data From Database To Highcharts Plugin in cakephp
- highcharts example for using data from database with mvc
- How to make the Y Axis values not start from 0 in highcharts? How to display forcefully display the last category data on X axis in HighCharts ?
- Highcharts display label for pie chart using html table as data source
- Display Highcharts data from mysql database on jsp page
- Highcharts Using Data from Ruby on Rails Database
- How to get Pie Chart data to display using AppCoda example and iOS Charts?
- How to Plot chart from two different webform Submission data And Wand to Display annotated point
- how to add data from database and set it to data serie in highchart C#
- How to return every nth row from dataset using postgresql to control a Highcharts data series
- How to replace x-axes with our own timestamp data from API in Highcharts using highstocks
- Highcharts to display area range and line chart with data from a CSV file
- how to make chart real time with 2 line and get data from php with highcharts
- Highcharts - How to change display data and remove mouseover?
- How to display tooltip data below x-axis category labels using Highcharts
- Using highcharts to display data from an API
- Dynamic chart using Highcharts with data from MySQL database
- Highcharts not being drawn in some cases when using data from MySQL (page elements created before database query complete?) PHP / MySQL
- How to generate Highcharts JS live data graphs from data on other website?
More Query from same tag
- Line Chart using array
- Highchart gap like highstock
- Please help Highcharts - Windrose graph display bars from top to center
- Uncaught TypeError: Cannot read property 'xAxis' of undefined Highcharts
- How to get Visible/ In-Visible legend elements in Highcharts
- How to add clickable HTML-link into tooltip in Highcharts 5.0.x?
- How to import or load Dumbbell chart in react app
- Custom color & tooltip for a single bar in Highcharts histogram
- Display values on the chart in Highcharts
- Highcharts context menu causes chart to disappear on return from print screen only on Chrome
- HighCharts - Don't show line or change line style if date not reached
- Implementing Custom Temperature Gauge with Angular 4 and HighCharts
- highcharts subtitle formatting
- Change Graph in the div using Drop Down List.
- How to customize which items appear in the built-in StockTools toolbar?
- How can I force highcharts to show every x-axis label regardless of spacing constraints?
- Formatting the float numbers in Highcharts
- Sitecore 8 experience editor and jquery
- In highCharts so much space left for each category when using index with data
- Changing Highcharts data series type dynamically
- High Charts - Show series data of Multiple Charts
- Highmaps in Typescript: Maps not being dipslayed
- Move the Highstock navigator position
- highgraphs chart not rendering
- DateTime whout seconds React highcharts
- Disabling inactive state in Highcharts styled mode
- highchart map create marker by click and get lat long coordinates
- Add dynamic data to line chart from mysql database with highcharts
- How to build an Organization Chart with highcharter
- Display space in chart in case of null value present in object in high chart stacked bar chart