{"id":16249,"date":"2018-04-05T09:52:52","date_gmt":"2018-04-05T07:52:52","guid":{"rendered":"http:\/\/www.highcharts.com\/blog\/?p=16249"},"modified":"2026-01-12T09:49:21","modified_gmt":"2026-01-12T09:49:21","slug":"highcharts-vue-wrapper","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/integration\/highcharts-vue-wrapper\/","title":{"rendered":"Highcharts Vue Wrapper"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>In this tutorial, I will show you how to use <a href=\"https:\/\/www.npmjs.com\/package\/highcharts-vue\">Highcharts Vue wrapper<\/a> to generate interactive web charts. Since the best way to learn is by doing, I will walk you through the <a href=\"https:\/\/github.com\/highcharts\/highcharts-vue\/tree\/master\/demo\">demo app<\/a> included in the repository; the result is displayed in this GIF below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20116 aligncenter\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2018\/04\/20092349\/HC-vue-wrapper-1.gif\" alt=\"HC vue wrapper\" width=\"500\" height=\"281\" \/><\/p>\n<p><i><b>Remark<\/b><\/p>\n<p>The following technologies\/tools are used in the demo: NodeJS, Vue, Vue-CLI, and Webpack. Basic knowledge of Javascript and ES6 are recommended to follow along.<\/i><\/p>\n<p>The article is divided into two main sections. The first section is about setting up the environment, and the second is about how to use the wrapper itself.<\/p>\n<p>Let\u2019s get started.<\/p>\n<h2>The environment setting<\/h2>\n<p>A bundler (<a href=\"https:\/\/webpack.js.org\/\">Webpack<\/a>), a transpiler (<a href=\"https:\/\/babeljs.io\/\">babeljs<\/a>), and a loader (<a href=\"https:\/\/vue-loader.vuejs.org\/en\/\">vue-loader<\/a>) are used to build the environment. The description of those tools is beyond the scope of this article. All you need to know right now is that <a href=\"https:\/\/www.npmjs.com\/package\/vue-cli\">Vue-cli<\/a> does all the heavy lifting configurations for you, such as the webpack configuration, the application skeleton, etc.<\/p>\n<p>To set up the environment, create a new directory and navigate to it (using the terminal), then install Vue-cli using this command: <code>npm install -g vue-cli<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092826\/install-vue-cli.jpg\" alt=\"install vue-cli\" width=\"1160\" height=\"301\" class=\"alignnone size-full wp-image-20120\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092826\/install-vue-cli.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092826\/install-vue-cli-560x145.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092826\/install-vue-cli-760x197.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092826\/install-vue-cli-768x199.jpg 768w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092826\/install-vue-cli-360x93.jpg 360w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Then type the following command to run a new vue project <code>vue init webpack-simple\u00a0<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092733\/new-vue-project.jpg\" alt=\"new vue project\" width=\"1160\" height=\"480\" class=\"alignnone size-full wp-image-20119\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092733\/new-vue-project.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092733\/new-vue-project-560x232.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092733\/new-vue-project-760x314.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092733\/new-vue-project-768x318.jpg 768w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092733\/new-vue-project-360x149.jpg 360w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Enter the directory created by <code>cd yourFolder<\/code>. Run the following commands to install Highcharts and Highcharts Vue wrapper:<\/p>\n<p><code>npm install --save highcharts<\/code><br \/>\n<code>npm install highcharts-vue<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092712\/install-highcharts-and-highcharts-vue.jpg\" alt=\"install highcharts and highcharts-vue\" width=\"1160\" height=\"342\" class=\"alignnone size-full wp-image-20118\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092712\/install-highcharts-and-highcharts-vue.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092712\/install-highcharts-and-highcharts-vue-560x165.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092712\/install-highcharts-and-highcharts-vue-760x224.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092712\/install-highcharts-and-highcharts-vue-768x226.jpg 768w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092712\/install-highcharts-and-highcharts-vue-360x106.jpg 360w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Once the installation has finished, you will see that configuration files have been automatically added to your directory, such as index.html, App.vue, main.js, etc. Cool, right?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092849\/files-after-setting.jpg\" alt=\"files after setting\" width=\"1160\" height=\"418\" class=\"alignnone size-full wp-image-20121\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092849\/files-after-setting.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092849\/files-after-setting-560x202.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092849\/files-after-setting-760x274.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092849\/files-after-setting-768x277.jpg 768w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2020\/07\/20092849\/files-after-setting-360x130.jpg 360w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>That is it; the environment setup is complete :).<\/p>\n<h2>How to use the wrapper<\/h2>\n<p>Let\u2019s try out the wrapper! Open the main.js file and add the following code:<\/p>\n<pre>import Vue from 'vue'\r\nimport HighchartsVue from 'highcharts-vue'<\/pre>\n<p>Then, register the wrapper on the global scope using <a href=\"https:\/\/vuejs.org\/v2\/api\/#Vue-use\">Vue.use<\/a>: <code>vue.use&lt;(HighchartsVue) <\/code><\/p>\n<p>The demo displays three different charts: a spline chart, a stock chart, and a map chart. For better visibility and maintenance, let\u2019s create a component for each chart. Enter to the src directory and create a new directory called components. Add three empty files: Chart.vue, MapChart.vue, and StockChart.vue.<br \/>\nEach file has three sections: template element, script element, and a style element.<\/p>\n<p><b>Template<\/b><\/p>\n<p>After the wrapper has been registered, you can use the Highcharts-vue component by adding the custom tag into the components.<\/p>\n<p>The constructor-type attribute is set by default for <b>chart<\/b>, so no need to add it. However, the constructor-type attribute is required for the stock and maps charts:<\/p>\n<pre>:constructor-type=\"'mapChart'\"\r\n:constructor-type=\"'stockChart'\"<\/pre>\n<p><b>Script <\/b><\/p>\n<p>The script element is where the chart\u2019s options and data are stored:<\/p>\n<pre>data() {\r\n  return {\r\n    title: '',\r\n    points: [10, 0, 8, 2, 6, 4, 5, 5],\r\n    chartType: 'Spline',\r\n    seriesColor: '#6fcd98',\r\n    colorInputIsSupported: null,\r\n    chartOptions: {\r\n      chart: {\r\n        type: 'spline'\r\n      },\r\n      title: {\r\n        text: 'Sin chart'\r\n      },\r\n      series: [{\r\n        data: [10, 0, 8, 2, 6, 4, 5, 5],\r\n        color: '#6fcd98'\r\n      }]\r\n    }\r\n  }\r\n},\r\n<\/pre>\n<p>Don\u2019t forget to wrap those options and data into a component object to use it later:<code> Export default { \u2026 } <\/code><\/p>\n<p><b>Style <\/b><\/p>\n<p>There is nothing specific about the style element, as it is mainly CSS. It\u2019s worth mentioning that this element makes use of the &lt;style scoped&gt; attribute, which limits the scope of the style to that component only. You can copy the content of the three components files from this <a href=\"https:\/\/github.com\/highcharts\/highcharts-vue\/tree\/master\/demo\/src\/components\">GitHub link<\/a>.<\/p>\n<p>Next, import those components into the App.vue file:<\/p>\n<pre>import Chart from '.\/components\/Chart.vue'\r\nimport StockChart from '.\/components\/StockChart'\r\nimport MapChart from '.\/components\/MapChart'\r\n....\r\n components: {\r\n    chart: Chart,\r\n    stockChart: StockChart,\r\n    mapChart: MapChart\r\n  },<\/pre>\n<p>For the rest of the code, feel free to copy the code from this <a href=\"https:\/\/github.com\/highcharts\/highcharts-vue\/tree\/master\/demo\/src\/components\">GitHub link<\/a>.<\/p>\n<p>Before running the demo, install the packages with the command: <code>npm install<\/code><\/p>\n<p>Launch the demo: <code>npm run build<\/code><\/p>\n<p>That\u2019s it. Go and create your own charts with Highcharts-vue wrapper!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step by step tutorial to learn how to use Highcharts Vue wrapper<\/p>\n","protected":false},"author":32,"featured_media":16270,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[1105],"tags":[1094,1031,1097],"coauthors":[699],"class_list":["post-16249","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration","tag-highcharts-core","tag-javascript","tag-vue"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/16249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=16249"}],"version-history":[{"count":1,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/16249\/revisions"}],"predecessor-version":[{"id":29125,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/16249\/revisions\/29125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/16270"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=16249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=16249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=16249"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=16249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}