Skip to content

HighCharts - Environment Setup

Setting up Highcharts in your web project is straightforward. Highcharts is a standalone JavaScript library, meaning it no longer requires jQuery or any other external framework to function.

You can include Highcharts in your project using several methods:

The Content Delivery Network (CDN) is the quickest way to get started. Highcharts hosts its files on servers distributed globally, ensuring fast loading times for your users.

Include the main Highcharts script in the <head> or before the closing </body> tag of your HTML file:

<!-- Always check code.highcharts.com for the latest version -->
<script src="https://code.highcharts.com/highcharts.js"></script>

Many features like exporting, accessibility enhancements, or specific chart types (e.g., heatmap, treemap) are available as separate modules. Include them after the core library:

<!-- Example: Adding Exporting and Accessibility modules -->
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<!-- Example: Adding a specific chart type module -->
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Highcharts CDN Example</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
</head>
<body>
<div id="container" style="width:100%; height:400px;"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const chart = Highcharts.chart('container', {
// Your Highcharts configuration object goes here
chart: {
type: 'bar' // Example chart type
},
title: {
text: 'My First Highchart'
},
series: [{
name: 'Example Series',
data: [1, 3, 2, 4]
}]
});
});
</script>
</body>
</html>

Method 2: Using NPM or Yarn (for Module Bundlers)

Section titled “Method 2: Using NPM or Yarn (for Module Bundlers)”

If you are using a build process with tools like Webpack, Rollup, or Parcel, installing Highcharts via a package manager is the recommended approach.

Open your terminal in your project directory and run:

# Using npm
npm install highcharts
# Using yarn
yarn add highcharts

In your JavaScript or TypeScript file, import the Highcharts library and initialize any necessary modules:

// Import Highcharts core library
import Highcharts from 'highcharts';
// Import optional modules
import Exporting from 'highcharts/modules/exporting';
import Accessibility from 'highcharts/modules/accessibility';
import Heatmap from 'highcharts/modules/heatmap'; // Example chart type module
// Initialize the modules
Exporting(Highcharts);
Accessibility(Highcharts);
Heatmap(Highcharts); // Initialize chart type modules too
// Find your container element (assuming you have <div id="container"></div> in your HTML)
const container = document.getElementById('container');
// Check if the container exists before creating the chart
if (container) {
// Create the chart
const chart = Highcharts.chart(container, {
// Your Highcharts configuration object goes here
chart: {
type: 'heatmap' // Example chart type
},
title: {
text: 'Highcharts NPM Example'
},
// ... other configuration options
series: [ /* ... series data ... */ ]
});
} else {
console.error('Chart container #container not found.');
}

Highcharts also provides official wrappers for popular frameworks like React, Angular, and Vue, simplifying integration. Check the official Highcharts documentation for specific instructions for your framework.

Choose the method that best fits your project structure and development workflow.