forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Samples: Updated and moved
studies/live-data
to samples
- Loading branch information
1 parent
59e44fb
commit 53906a3
Showing
4 changed files
with
65 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
name: Highcharts Demo | ||
authors: | ||
- Torstein Hønsi | ||
- Gøran Slettemark | ||
requiresManualTesting: true | ||
js_wrap: b | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script src="https://code.highcharts.com/highcharts.js"></script> | ||
|
||
<div id="container"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
let chart; // global | ||
|
||
/** | ||
* Request data from the server, add it to the graph and set a timeout to request again | ||
*/ | ||
async function requestData() { | ||
const result = await fetch('https://demo-live-data.highcharts.com/time-rows.json'); | ||
if (result.ok) { | ||
const data = await result.json(); | ||
|
||
const [date, value] = data[0]; | ||
const point = [new Date(date).getTime(), value * 10]; | ||
const series = chart.series[0], | ||
shift = series.data.length > 20; // shift if the series is longer than 20 | ||
|
||
// add the point | ||
chart.series[0].addPoint(point, true, shift); | ||
// call it again after one second | ||
setTimeout(requestData, 1000); | ||
} | ||
} | ||
|
||
window.addEventListener('load', function () { | ||
chart = new Highcharts.Chart({ | ||
chart: { | ||
renderTo: 'container', | ||
defaultSeriesType: 'spline', | ||
events: { | ||
load: requestData | ||
} | ||
}, | ||
title: { | ||
text: 'Live random data' | ||
}, | ||
xAxis: { | ||
type: 'datetime', | ||
tickPixelInterval: 150, | ||
maxZoom: 20 * 1000 | ||
}, | ||
yAxis: { | ||
minPadding: 0.2, | ||
maxPadding: 0.2, | ||
title: { | ||
text: 'Value', | ||
margin: 80 | ||
} | ||
}, | ||
series: [{ | ||
name: 'Random data', | ||
data: [] | ||
}] | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters