Add scatter chart

This commit is contained in:
Jakub Juszczak
2017-07-25 12:53:17 +02:00
parent 3f15eb9abc
commit 098c90edf1
2 changed files with 62 additions and 1 deletions

59
src/BaseCharts/Scatter.js Normal file
View File

@@ -0,0 +1,59 @@
import Vue from 'vue'
import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
</div>
`,
props: {
chartId: {
default: 'scatter-chart',
type: String
},
width: {
default: 400,
type: Number
},
height: {
default: 400,
type: Number
}
},
data () {
return {
defaultOptions: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom'
}]
}
}
}
},
methods: {
render (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'scatter',
data: data,
options: chartOptions
}
)
this._chart.generateLegend()
}
},
beforeDestroy () {
if (this._chart) {
this._chart.destroy()
}
}
})

View File

@@ -5,6 +5,7 @@ import Pie from './BaseCharts/Pie'
import PolarArea from './BaseCharts/PolarArea'
import Radar from './BaseCharts/Radar'
import Bubble from './BaseCharts/Bubble'
import Scatter from './BaseCharts/Scatter'
const VueCharts = {
Bar,
@@ -13,7 +14,8 @@ const VueCharts = {
Pie,
PolarArea,
Radar,
Bubble
Bubble,
Scatter
}
module.exports = VueCharts