Highcharts-Vue Integration
highcharts-vue is the official integration package for using the Highcharts charting library within Vue.js applications. Currently at version 2.0.1, it provides first-class support exclusively for Vue 3 applications. The 2.x.x series represents a major shift, with previous 1.x.x versions supporting Vue 2. This package requires both `vue` (>=3.0.0) and `highcharts` (>=5.0.0) as peer dependencies, which must be installed separately. It facilitates declarative chart rendering, module loading, and interaction with the underlying Highcharts chart instance. The project maintains an active release cadence, with recent updates focusing on Vue 3 features and documentation. Its primary differentiator is being the official Highcharts integration, ensuring optimal compatibility and adherence to best practices for Vue developers.
Common errors
-
Cannot read properties of undefined (reading 'use')
cause Attempting to use `Vue.use(HighchartsVue)` with a Vue 3 `app` instance, or `app.use(HighchartsVue)` with a Vue 2 global `Vue` object.fixFor Vue 3, ensure you are using `app.use(HighchartsVue)` where `app` is the result of `createApp()`. For Vue 2, use `Vue.use(HighchartsVue)`. -
Component is missing template or render function.
cause The Highcharts component (`<highcharts>` or `<Chart>`) was used without the required `:options` prop, or the prop was empty/invalid.fixProvide a valid Highcharts configuration object to the component via the `:options` prop: `<HighchartsChart :options='chartOptions' />`. This prop is mandatory. -
ReferenceError: Highcharts is not defined (or a module feature is missing)
cause The main `Highcharts` object or a specific Highcharts module was not imported or initialized correctly before being used by the `highcharts-vue` component.fixEnsure `import Highcharts from 'highcharts'` is present. For Highcharts modules, confirm that `import moduleInit from 'highcharts/modules/modulename'` and `moduleInit(Highcharts)` are called before the chart is rendered.
Warnings
- breaking Version 2.0.0 of `highcharts-vue` introduced a breaking change by dropping support for Vue 2, exclusively targeting Vue 3 and above. Applications using Vue 2 must remain on `highcharts-vue` versions 1.x.x.
- gotcha Highcharts modules (e.g., `exporting`, `stock`, `map`, `gantt`) are not automatically included by `highcharts-vue`. They must be explicitly imported from `highcharts/modules/` and then initialized by calling the module function with the main `Highcharts` instance.
- gotcha `highcharts-vue` lists `vue` and `highcharts` as peer dependencies. These core libraries are not installed automatically with `highcharts-vue` and must be explicitly installed in your project for the integration to function correctly.
Install
-
npm install highcharts-vue -
yarn add highcharts-vue -
pnpm add highcharts-vue
Imports
- HighchartsVue
import { HighchartsVue } from 'highcharts-vue'import HighchartsVue from 'highcharts-vue'
- Chart
import Chart from 'highcharts-vue'
import { Chart } from 'highcharts-vue' - Highcharts Modules
import { exporting } from 'highcharts/modules/exporting'import Highcharts from 'highcharts'; import exportingInit from 'highcharts/modules/exporting'; exportingInit(Highcharts);
Quickstart
import { createApp, defineComponent, ref } from 'vue';
import Highcharts from 'highcharts';
import { Chart } from 'highcharts-vue';
import exportingInit from 'highcharts/modules/exporting';
// Initialize the exporting module for Highcharts
exportingInit(Highcharts);
const App = defineComponent({
components: {
HighchartsChart: Chart // Renamed for clarity, can use 'Chart' directly
},
setup() {
const chartOptions = ref({
chart: {
type: 'line'
},
title: {
text: 'My First Highcharts Vue Chart'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May']
},
series: [{
name: 'Sample Data',
data: [1, 3, 2, 4, 5]
}],
credits: {
enabled: false // Disable Highcharts credits
},
exporting: {
enabled: true // Enable exporting functionality via the module
}
});
return {
chartOptions
};
},
template: `
<div id="app">
<h1>Highcharts-Vue Demo</h1>
<HighchartsChart :options="chartOptions" />
</div>
`,
});
createApp(App).mount('#app');