Skip to content

Instantly share code, notes, and snippets.

@jon-a-nygaard
Last active November 18, 2016 13:40
Show Gist options
  • Save jon-a-nygaard/be9eb01f644998a15a5b51e0d45d68cf to your computer and use it in GitHub Desktop.
Save jon-a-nygaard/be9eb01f644998a15a5b51e0d45d68cf to your computer and use it in GitHub Desktop.
Example of Highcharts and its boost module loaded using Webpack.

Install

  1. Download source files
  2. Run npm install to install all dependencies.
  3. Run node build or npm run build to bundle app.js into bundle.js

Open application

  1. Open index.html in a browser.
'use strict';
const Highcharts = require('highcharts');
require('highcharts/modules/boost')(Highcharts);
const range = n => Array.from({ length: n }).map((_, i) => i);
const getData = (n) => {
let arr = [],
a,
b,
c,
spike;
return arr = range(n).reduce((arr, i) => {
if (i % 100 === 0) {
a = 2 * Math.random();
}
if (i % 1000 === 0) {
b = 2 * Math.random();
}
if (i % 10000 === 0) {
c = 2 * Math.random();
}
if (i % 50000 === 0) {
spike = 10;
} else {
spike = 0;
}
arr.push([
i,
2 * Math.sin(i / 100) + a + b + c + spike + Math.random()
]);
return arr;
}, [])
};
const data = getData(500000);
console.time('area');
Highcharts.chart('container', {
chart: {
type: 'area',
zoomType: 'x'
},
title: {
text: 'Trimmed Highcharts drawing ' + data.length + ' points'
},
subtitle: {
text: 'Using the experimental Highcharts Boost module'
},
tooltip: {
valueDecimals: 2
},
series: [{
data: data
}]
})
console.timeEnd('area');
'use strict';
const webpack = require('webpack');
webpack({
entry: "./app.js",
output: {
path: __dirname,
filename: "bundle.js"
},
}, (err) => {
if (err) {
console.log(err)
}
});
<!DOCTYPE html>
<html>
<head>
<title>Highcharts Boost module with Webpack</title>
</head>
<body>
<div id="container"></div>
<script src="./bundle.js" type="text/javascript"></script>
</body>
</html>
{
"name": "highcharts-boost-webpack",
"version": "1.0.0",
"description": "Load Highcharts Boost Module with Webpack",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node build.js"
},
"author": "Jon Arild Nygård",
"license": "ISC",
"devDependencies": {
"webpack": "^1.13.3"
},
"dependencies": {
"highcharts": "^5.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment