Skip to content

Commit

Permalink
✨ Add Doughnut Chart component
Browse files Browse the repository at this point in the history
  • Loading branch information
apertureless committed Jul 1, 2016
1 parent 70a3b98 commit 84ae683
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ export default {

### Line Chart

![Bar](src/assets/line.png)
![Line](src/assets/line.png)

### Doughnut

![Doughnut](src/assets/doughnut.png)

## Todo

Expand All @@ -85,7 +89,7 @@ export default {
- [ ] Implement Radar Chart
- [ ] Implement Polar Area Chart
- [ ] Implement Pie Chart
- [ ] Implement Doughnut Chart
- [x] Implement Doughnut Chart
- [ ] Make npm module
- [ ] Add tests

Expand Down
6 changes: 4 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<template>
<div class="container">
<bar-example :width="100" :height="200" :player={wins:'12'} :opponent={wins:'23'}></bar-example>
<bar-example></bar-example>
<line-example></line-example>
<doughnut-example></doughnut-example>
</div>
</template>

<script>
import BarExample from './examples/BarExample'
import LineExample from './examples/LineExample'
import DoughnutExample from './examples/DoughnutExample'
export default {
components: { BarExample, LineExample }
components: { BarExample, LineExample, DoughnutExample }
}
</script>

Expand Down
41 changes: 41 additions & 0 deletions src/BaseCharts/Doughnut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Vue from 'vue'
import Chart from 'chart.js'

export default Vue.extend({
template: `
<div>
<canvas id="doughnut-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: 'doughnut',
data: data,
options: options
}
)
chart.generateLegend()
}
}
})
Binary file added src/assets/doughnut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/examples/DoughnutExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import DoughnutChart from '../BaseCharts/Doughnut'

export default DoughnutChart.extend({
ready () {
this.render({
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
datasets: [
{
backgroundColor: [
'#41B883',
'#E46651',
'#00D8FF',
'#DD1B16'
],
data: [40, 20, 80, 10]
}
]
})
}
})

0 comments on commit 84ae683

Please sign in to comment.