Gathering detailed insights and metrics for vue-apexcharts
Gathering detailed insights and metrics for vue-apexcharts
Gathering detailed insights and metrics for vue-apexcharts
Gathering detailed insights and metrics for vue-apexcharts
npm install vue-apexcharts
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,335 Stars
281 Commits
136 Forks
22 Watching
3 Branches
17 Contributors
Updated on 27 Nov 2024
Vue (64.98%)
JavaScript (32.85%)
HTML (2.17%)
Cumulative downloads
Total Downloads
Last day
-0.6%
21,164
Compared to previous day
Last week
0.6%
108,176
Compared to previous week
Last month
11.1%
464,742
Compared to previous month
Last year
-3.4%
5,007,919
Compared to previous year
2
Vue.js wrapper for ApexCharts to build interactive visualizations in vue.
1npm install --save apexcharts 2npm install --save vue-apexcharts
If you're looking for Vue 3.x.x compatibile component, check-out vue3-apexcharts
1import VueApexCharts from 'vue-apexcharts' 2Vue.use(VueApexCharts) 3 4Vue.component('apexchart', VueApexCharts)
To create a basic bar chart with minimal configuration, write as follows:
1<template> 2 <div> 3 <apexchart width="500" type="bar" :options="chartOptions" :series="series"></apexchart> 4 </div> 5</template>
1 2export default { 3 data: function() { 4 return { 5 chartOptions: { 6 chart: { 7 id: 'vuechart-example' 8 }, 9 xaxis: { 10 categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998] 11 } 12 }, 13 series: [{ 14 name: 'series-1', 15 data: [30, 40, 35, 50, 49, 60, 70, 91] 16 }] 17 } 18 }, 19};
This will render the following chart
Simple! Just change the series
or any option
and it will automatically re-render the chart.
Click on the below example to see this in action
1<template> 2 <div class="app"> 3 <apexchart width="550" type="bar" :options="chartOptions" :series="series"></apexchart> 4 <div> 5 <button @click="updateChart">Update!</button> 6 </div> 7 </div> 8 9</template>
1export default { 2 data: function() { 3 return { 4 chartOptions: { 5 chart: { 6 id: 'vuechart-example', 7 }, 8 xaxis: { 9 categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998], 10 }, 11 }, 12 series: [{ 13 name: 'series-1', 14 data: [30, 40, 45, 50, 49, 60, 70, 81] 15 }] 16 } 17 }, 18 methods: { 19 updateChart() { 20 const max = 90; 21 const min = 20; 22 const newData = this.series[0].data.map(() => { 23 return Math.floor(Math.random() * (max - min + 1)) + min 24 }) 25 26 const colors = ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0'] 27 28 // Make sure to update the whole options config and not just a single property to allow the Vue watch catch the change. 29 this.chartOptions = { 30 colors: [colors[Math.floor(Math.random()*colors.length)]] 31 }; 32 // In the same way, update the series option 33 this.series = [{ 34 data: newData 35 }] 36 } 37 } 38};
Important: While updating the options, make sure to update the outermost property even when you need to update the nested property.
✅ Do this
1this.chartOptions = {...this.chartOptions, ...{ 2 xaxis: { 3 labels: { 4 style: { 5 colors: ['red'] 6 } 7 } 8 } 9}}
❌ Not this
1this.chartOptions.xaxis = { 2 labels: { 3 style: { 4 colors: ['red'] 5 } 6 } 7}}
Prop | Type | Description |
---|---|---|
series* | Array | The series is an array which accepts an object in the following format. To know more about the format of dataSeries, checkout Series docs on the website. |
type* | String | line , area , bar , pie , donut , scatter , bubble , heatmap , radialBar , candlestick |
width | Number/String | Possible values for width can be 100% or 400px or 400 |
height | Number/String | Possible values for height can be 100% or 300px or 300 |
options | Object | The configuration object, see options on API (Reference) |
You don't actually need to call updateSeries() or updateOptions() manually. Changing the props will automatically update the chart. You only need to call these methods to update the chart forcefully.
Method | Description |
---|---|
updateSeries | Allows you to update the series array overriding the existing one |
updateOptions | Allows you to update the configuration object |
toggleSeries | Allows you to toggle the visibility of series programatically. Useful when you have custom legend. |
appendData | Allows you to append new data to the series array. |
addText | The addText() method can be used to draw text after chart is rendered. |
addXaxisAnnotation | Draw x-axis annotations after chart is rendered. |
addYaxisAnnotation | Draw y-axis annotations after chart is rendered. |
addPointAnnotation | Draw point (xy) annotations after chart is rendered. |
How to call the methods mentioned above?
1<template> 2 <div class="example"> 3 <apexchart ref="demoChart" width="500" :options="chartOptions" :series="series"></apexchart> 4 </div> 5</template> 6 7<script> 8 functionName: function() { 9 this.$refs.demoChart.updateOptions({ colors: newColors }) 10 }, 11</script>
Sometimes, you may want to call methods of the core ApexCharts library from some other place, and you can do so on this.$apexcharts
global variable directly. You need to target the chart by chart.id
while calling this method
Example
1this.$apexcharts.exec('vuechart-example', 'updateSeries', [{ 2 data: [40, 55, 65, 11, 23, 44, 54, 33] 3}])
In the above method, vuechart-example
is the ID of chart, updateSeries
is the name of the method you want to call and the third parameter is the new Series you want to update.
More info on the .exec()
method can be found here
All other methods of ApexCharts can be called the same way.
The repository includes the following files and directories.
vue-apexcharts/
├── dist/
│ └── vue-apexcharts.js
└── src/
├── ApexCharts.component.js
├── Utils.js
└── index.js
Basic Examples are included to show how to get started using ApexCharts with Vue easily.
To run the examples,
1cd example 2npm install 3npm run serve
1npm install
1npm run build
ApexCharts is an open source project.
You can help by becoming a sponsor on Patreon or doing a one time donation on PayPal
Vue-ApexCharts is released under MIT license. You are free to use, modify and distribute this software, as long as the copyright header is left intact.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 1/3 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
16 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More