2018-01-28 14:58:34 +08:00
|
|
|
import G2 from '@antv/g2'
|
2018-01-29 16:33:42 +08:00
|
|
|
import * as DataSet from '@antv/data-set'
|
2018-01-28 22:45:54 +08:00
|
|
|
// 关闭 G2 的体验改进计划打点请求
|
|
|
|
|
G2.track(false)
|
|
|
|
|
|
2018-01-28 09:40:57 +08:00
|
|
|
export default {
|
2018-01-28 22:45:54 +08:00
|
|
|
props: {
|
2018-01-29 11:39:36 +08:00
|
|
|
// 图表数据
|
2018-01-28 22:45:54 +08:00
|
|
|
data: {
|
|
|
|
|
type: Array,
|
|
|
|
|
required: false,
|
|
|
|
|
default: () => []
|
2018-01-29 11:39:36 +08:00
|
|
|
},
|
|
|
|
|
// [图表设置项] 高度
|
|
|
|
|
height: {
|
|
|
|
|
type: Number,
|
|
|
|
|
required: false,
|
|
|
|
|
default: 300
|
|
|
|
|
},
|
|
|
|
|
// [图表设置项] 开启自动填充父元素高度
|
|
|
|
|
autoHeight: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false,
|
|
|
|
|
default: false
|
2018-01-29 14:11:38 +08:00
|
|
|
},
|
|
|
|
|
// [图表设置项] 自动宽度
|
|
|
|
|
forceFit: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false,
|
|
|
|
|
default: true
|
2018-01-28 22:45:54 +08:00
|
|
|
}
|
|
|
|
|
},
|
2018-01-28 14:58:34 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
2018-01-29 11:39:36 +08:00
|
|
|
// 在页面中不需要再引入 直接使用 this.G2
|
2018-01-28 14:58:34 +08:00
|
|
|
G2,
|
2018-01-29 11:39:36 +08:00
|
|
|
// 数据处理模块
|
2018-01-29 16:33:42 +08:00
|
|
|
DataSet,
|
2018-01-28 14:58:34 +08:00
|
|
|
// 图表实例
|
2018-01-29 14:30:53 +08:00
|
|
|
chart: null,
|
2018-01-29 16:33:42 +08:00
|
|
|
// 在组件 mounted 后立即初始化图表
|
|
|
|
|
autoInit: true,
|
2018-01-29 14:30:53 +08:00
|
|
|
// [图表设置项] padding
|
|
|
|
|
padding: [40, 40, 40, 40]
|
2018-01-28 14:58:34 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
2018-01-28 22:45:54 +08:00
|
|
|
// 如果设置了在 mounted 后自动初始化 就在这里初始化
|
2018-01-29 11:39:36 +08:00
|
|
|
if (this.autoInit) {
|
2018-01-28 22:45:54 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.initHandler()
|
|
|
|
|
}, 0)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
// 数据改变
|
|
|
|
|
data () {
|
|
|
|
|
this.changeData()
|
|
|
|
|
}
|
2018-01-28 14:58:34 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2018-01-28 22:45:54 +08:00
|
|
|
// 重绘大小
|
2018-01-29 14:11:38 +08:00
|
|
|
resize (width, height) {
|
2018-01-28 14:58:34 +08:00
|
|
|
if (this.chart) {
|
2018-01-29 14:11:38 +08:00
|
|
|
this.chart.changeSize(width || this.G2.DomUtil.getWidth(this.$refs.chart), height || this.G2.DomUtil.getHeight(this.$refs.chart))
|
2018-01-28 14:58:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-28 09:40:57 +08:00
|
|
|
}
|
|
|
|
|
}
|