mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2026-02-09 19:13:31 +00:00
✨ Add chart type Bubble
This commit is contained in:
64
src/BaseCharts/Bubble.js
Normal file
64
src/BaseCharts/Bubble.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import Chart from 'chart.js'
|
||||||
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
|
export default Vue.extend({
|
||||||
|
template: `
|
||||||
|
<div>
|
||||||
|
<canvas id="bar-chart" width=width height=height ref="canvas"></canvas>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
|
||||||
|
props: {
|
||||||
|
width: {
|
||||||
|
default: 400,
|
||||||
|
type: Number
|
||||||
|
},
|
||||||
|
height: {
|
||||||
|
default: 400,
|
||||||
|
type: Number
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
defaultOptions: {
|
||||||
|
scales: {
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
beginAtZero: true
|
||||||
|
},
|
||||||
|
gridLines: {
|
||||||
|
display: false
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
xAxes: [ {
|
||||||
|
gridLines: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
categoryPercentage: 0.5,
|
||||||
|
barPercentage: 0.2
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
renderChart (data, options) {
|
||||||
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
|
this._chart = new Chart(
|
||||||
|
this.$refs.canvas.getContext('2d'), {
|
||||||
|
type: 'bubble',
|
||||||
|
data: data,
|
||||||
|
options: chartOptions
|
||||||
|
}
|
||||||
|
)
|
||||||
|
this._chart.generateLegend()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
this._chart.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -10,15 +10,16 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BarExample from './examples/BarExample'
|
import BarExample from './BarExample'
|
||||||
import LineExample from './examples/LineExample'
|
import LineExample from './LineExample'
|
||||||
import DoughnutExample from './examples/DoughnutExample'
|
import DoughnutExample from './DoughnutExample'
|
||||||
import PieExample from './examples/PieExample'
|
import PieExample from './PieExample'
|
||||||
import RadarExample from './examples/RadarExample'
|
import RadarExample from './RadarExample'
|
||||||
import PolarAreaExample from './examples/PolarAreaExample'
|
import PolarAreaExample from './PolarAreaExample'
|
||||||
|
import BubbleExample from './BubbleExample'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { BarExample, LineExample, DoughnutExample, PieExample, RadarExample, PolarAreaExample }
|
components: { BarExample, LineExample, DoughnutExample, PieExample, RadarExample, PolarAreaExample, BubbleExample }
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
52
src/examples/BubbleExample.js
Normal file
52
src/examples/BubbleExample.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import BubbleChart from '../BaseCharts/Bubble'
|
||||||
|
|
||||||
|
export default BubbleChart.extend({
|
||||||
|
mounted () {
|
||||||
|
this.renderChart({
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Data One',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
x: 20,
|
||||||
|
y: 25,
|
||||||
|
r: 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 40,
|
||||||
|
y: 10,
|
||||||
|
r: 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 30,
|
||||||
|
y: 22,
|
||||||
|
r: 30
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Data Two',
|
||||||
|
backgroundColor: '#7C8CF8',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
x: 10,
|
||||||
|
y: 30,
|
||||||
|
r: 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 20,
|
||||||
|
y: 20,
|
||||||
|
r: 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 15,
|
||||||
|
y: 8,
|
||||||
|
r: 30
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -4,6 +4,7 @@ import Line from './BaseCharts/Line'
|
|||||||
import Pie from './BaseCharts/Pie'
|
import Pie from './BaseCharts/Pie'
|
||||||
import PolarArea from './BaseCharts/PolarArea'
|
import PolarArea from './BaseCharts/PolarArea'
|
||||||
import Radar from './BaseCharts/Radar'
|
import Radar from './BaseCharts/Radar'
|
||||||
|
import Bubble from './BaseCharts/Bubble'
|
||||||
|
|
||||||
const VueCharts = {
|
const VueCharts = {
|
||||||
Bar,
|
Bar,
|
||||||
@@ -11,7 +12,8 @@ const VueCharts = {
|
|||||||
Line,
|
Line,
|
||||||
Pie,
|
Pie,
|
||||||
PolarArea,
|
PolarArea,
|
||||||
Radar
|
Radar,
|
||||||
|
Bubble
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = VueCharts
|
module.exports = VueCharts
|
||||||
|
|||||||
Reference in New Issue
Block a user