Highcharts Downsample Demo
Author: Sveinn Steinarsson
by vasagi
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/boost.js"></script>
<script src="https://code.highcharts.com/modules/marker-clusters.js"></script>
<div id="container"></div>
JavaScript
function getData(n) {
const arr = [];
for (let i = 0; i < n; i += 1) {
arr.push([
Date.UTC(2023, 0, i + 1),
Math.pow(Math.random(), 2) * 90 + 5
]);
}
return arr;
}
function getSeries(n, s) {
let i = 0;
const r = [];
for (; i < s; i++) {
const datapoint = getData(n);
r.push({
data: datapoint,
type: 'scatter',
color: 'red',
boostThreshold: 1000
});
r.push({
data: datapoint,
type: 'scatter',
color: 'yellow',
boostThreshold: 1000
});
r.push({
data: getData(n),
type: 'scatter',
color: 'orange',
boostThreshold: 1000
});
}
return r;
}
const n = 700,
s = 1,
series = getSeries(n, s);
console.time('line');
Highcharts.chart('container', {
chart: {
type:'scatter',
zooming: {
type: 'x'
}
},
title: {
text:
'Highcharts drawing ' + (n * s) + ' points across ' + s + ' series'
},
legend: {
enabled: true
},
boost: {
useGPUTranslations: true
},
xAxis: {
type:'datetime',
ordinal: false
},
navigator: {
xAxis: {
ordinal: false,
min: 0,
max: 10
}
},
// yAxis: {
// min: 0,
// max: 8
// },
subtitle: {
text: 'Using the Boost module'
},
tooltip: {
valueDecimals: 2
},
series: series,
plotOptions: {
series: {
dataLabels: {
enabled: true,
pointFormat: ''
}
}
}
});
console.timeEnd('line');