Skip to content

Commit d6c3f50

Browse files
committed
✨ Add chart type Bubble
1 parent d700330 commit d6c3f50

File tree

4 files changed

+127
-8
lines changed

4 files changed

+127
-8
lines changed

src/BaseCharts/Bubble.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import Vue from 'vue'
2+
import Chart from 'chart.js'
3+
import { mergeOptions } from '../helpers/options'
4+
5+
export default Vue.extend({
6+
template: `
7+
<div>
8+
<canvas id="bar-chart" width=width height=height ref="canvas"></canvas>
9+
</div>
10+
`,
11+
12+
props: {
13+
width: {
14+
default: 400,
15+
type: Number
16+
},
17+
height: {
18+
default: 400,
19+
type: Number
20+
}
21+
},
22+
23+
data () {
24+
return {
25+
defaultOptions: {
26+
scales: {
27+
yAxes: [{
28+
ticks: {
29+
beginAtZero: true
30+
},
31+
gridLines: {
32+
display: false
33+
}
34+
}],
35+
xAxes: [ {
36+
gridLines: {
37+
display: false
38+
},
39+
categoryPercentage: 0.5,
40+
barPercentage: 0.2
41+
}]
42+
}
43+
}
44+
}
45+
},
46+
47+
methods: {
48+
renderChart (data, options) {
49+
let chartOptions = mergeOptions(this.defaultOptions, options)
50+
51+
this._chart = new Chart(
52+
this.$refs.canvas.getContext('2d'), {
53+
type: 'bubble',
54+
data: data,
55+
options: chartOptions
56+
}
57+
)
58+
this._chart.generateLegend()
59+
}
60+
},
61+
beforeDestroy () {
62+
this._chart.destroy()
63+
}
64+
})

src/examples/App.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
</template>
1111

1212
<script>
13-
import BarExample from './examples/BarExample'
14-
import LineExample from './examples/LineExample'
15-
import DoughnutExample from './examples/DoughnutExample'
16-
import PieExample from './examples/PieExample'
17-
import RadarExample from './examples/RadarExample'
18-
import PolarAreaExample from './examples/PolarAreaExample'
13+
import BarExample from './BarExample'
14+
import LineExample from './LineExample'
15+
import DoughnutExample from './DoughnutExample'
16+
import PieExample from './PieExample'
17+
import RadarExample from './RadarExample'
18+
import PolarAreaExample from './PolarAreaExample'
19+
import BubbleExample from './BubbleExample'
1920
2021
export default {
21-
components: { BarExample, LineExample, DoughnutExample, PieExample, RadarExample, PolarAreaExample }
22+
components: { BarExample, LineExample, DoughnutExample, PieExample, RadarExample, PolarAreaExample, BubbleExample }
2223
}
2324
</script>
2425

src/examples/BubbleExample.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import BubbleChart from '../BaseCharts/Bubble'
2+
3+
export default BubbleChart.extend({
4+
mounted () {
5+
this.renderChart({
6+
datasets: [
7+
{
8+
label: 'Data One',
9+
backgroundColor: '#f87979',
10+
data: [
11+
{
12+
x: 20,
13+
y: 25,
14+
r: 5
15+
},
16+
{
17+
x: 40,
18+
y: 10,
19+
r: 10
20+
},
21+
{
22+
x: 30,
23+
y: 22,
24+
r: 30
25+
}
26+
]
27+
},
28+
{
29+
label: 'Data Two',
30+
backgroundColor: '#7C8CF8',
31+
data: [
32+
{
33+
x: 10,
34+
y: 30,
35+
r: 15
36+
},
37+
{
38+
x: 20,
39+
y: 20,
40+
r: 10
41+
},
42+
{
43+
x: 15,
44+
y: 8,
45+
r: 30
46+
}
47+
]
48+
}
49+
]
50+
})
51+
}
52+
})

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import Line from './BaseCharts/Line'
44
import Pie from './BaseCharts/Pie'
55
import PolarArea from './BaseCharts/PolarArea'
66
import Radar from './BaseCharts/Radar'
7+
import Bubble from './BaseCharts/Bubble'
78

89
const VueCharts = {
910
Bar,
1011
Doughnut,
1112
Line,
1213
Pie,
1314
PolarArea,
14-
Radar
15+
Radar,
16+
Bubble
1517
}
1618

1719
module.exports = VueCharts

0 commit comments

Comments
 (0)