This tutorial teaches you to quickly add beautiful StockCharts to your Vue.js applications using CanvasJS & NPM.
In case you have any suggestions/feedback please post it in our forum.
Here are couple of things that you need to remember while using React StockChart Component.
<CanvasJSStockChart :options="stockChartOptions" @stockchart-ref="stockChartRef" :styles="{width: '100%', height: '460px'}"/>
Create Vue.js app. Please refer to Vue.js documentation for prerequisites, environment setup & tutorial on creating Vue.js project & app.
Install CanvasJS Vue StockCharts package via NPM by running the following command.
npm install @canvasjs/vue-stockcharts
Import the Vue StockCharts plugin to your Vue.js application & install it.
import { createApp } from 'vue' import App from './App.vue' import CanvasJSStockChart from '@canvasjs/vue-stockcharts'; const app = createApp(App); app.use(CanvasJSStockChart); // install the CanvasJS Vuejs StockChart Plugin app.mount('#app');
Set the stockchart-options in app.vue & use ‘CanvasJSStockChart’ selector to create stockchart inside template tag.
<!-- App.vue --> <script> export default { data() { return { chart: null, options: { title: { text: "CanvasJS StockChart in Vue.js" }, charts: [{ data: [{ type: "line", dataPoints: [ { x: new Date("2018-01-01"), y: 71 }, { x: new Date("2018-02-01"), y: 55 }, { x: new Date("2018-03-01"), y: 50 }, { x: new Date("2018-04-01"), y: 65 }, { x: new Date("2018-05-01"), y: 95 }, { x: new Date("2018-06-01"), y: 68 }, { x: new Date("2018-07-01"), y: 28 }, { x: new Date("2018-08-01"), y: 34 }, { x: new Date("2018-09-01"), y: 14 }, { x: new Date("2018-10-01"), y: 71 }, { x: new Date("2018-11-01"), y: 55 }, { x: new Date("2018-12-01"), y: 50 }, { x: new Date("2019-01-01"), y: 34 }, { x: new Date("2019-02-01"), y: 50 }, { x: new Date("2019-03-01"), y: 50 }, { x: new Date("2019-04-01"), y: 95 }, { x: new Date("2019-05-01"), y: 68 }, { x: new Date("2019-06-01"), y: 28 }, { x: new Date("2019-07-01"), y: 34 }, { x: new Date("2019-08-01"), y: 65 }, { x: new Date("2019-09-01"), y: 55 }, { x: new Date("2019-10-01"), y: 71 }, { x: new Date("2019-11-01"), y: 55 }, { x: new Date("2019-12-01"), y: 50 } ] }] }], navigator: { slider: { minimum: new Date("2018-07-01"), maximum: new Date("2019-06-30") } } } } } </script> <template> <CanvasJSStockChart :options="options" /> </template>
In order to make it simpler we have also created examples with different use-cases. Please check out our Vue.js StockChart Gallery for the same.