mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2025-10-29 18:00:20 +00:00
✨ Add Pie Chart component
This commit is contained in:
@@ -82,13 +82,17 @@ export default {
|
||||
|
||||

|
||||
|
||||
### Pie
|
||||
|
||||

|
||||
|
||||
## Todo
|
||||
|
||||
- [x] Implement Bar Chart
|
||||
- [x] Implement Line Chart
|
||||
- [ ] Implement Radar Chart
|
||||
- [ ] Implement Polar Area Chart
|
||||
- [ ] Implement Pie Chart
|
||||
- [x] Implement Pie Chart
|
||||
- [x] Implement Doughnut Chart
|
||||
- [ ] Make npm module
|
||||
- [ ] Add tests
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<bar-example></bar-example>
|
||||
<line-example></line-example>
|
||||
<doughnut-example></doughnut-example>
|
||||
<pie-example></pie-example>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -10,9 +11,10 @@
|
||||
import BarExample from './examples/BarExample'
|
||||
import LineExample from './examples/LineExample'
|
||||
import DoughnutExample from './examples/DoughnutExample'
|
||||
import PieExample from './examples/PieExample'
|
||||
|
||||
export default {
|
||||
components: { BarExample, LineExample, DoughnutExample }
|
||||
components: { BarExample, LineExample, DoughnutExample, PieExample }
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="pie-chart" width=width height=height v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
},
|
||||
height: {
|
||||
default: 400,
|
||||
type: Number
|
||||
}
|
||||
},
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
const chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'pie',
|
||||
data: data,
|
||||
options: options
|
||||
}
|
||||
)
|
||||
chart.generateLegend()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
BIN
src/assets/pie.png
Normal file
BIN
src/assets/pie.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
20
src/examples/PieExample.js
Normal file
20
src/examples/PieExample.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import PieChart from '../BaseCharts/Pie'
|
||||
|
||||
export default PieChart.extend({
|
||||
ready () {
|
||||
this.render({
|
||||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
||||
datasets: [
|
||||
{
|
||||
backgroundColor: [
|
||||
'#41B883',
|
||||
'#E46651',
|
||||
'#00D8FF',
|
||||
'#DD1B16'
|
||||
],
|
||||
data: [40, 20, 80, 10]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user