diff --git a/src/components/G2/charts/Column/1.vue b/src/components/G2/charts/Column/1.vue index ef551a6b..7dcdbd2f 100644 --- a/src/components/G2/charts/Column/1.vue +++ b/src/components/G2/charts/Column/1.vue @@ -19,12 +19,7 @@ export default { methods: { // 初始化图表 initHandler () { - this.chart = new this.G2.Chart({ - container: this.$refs.chart, - forceFit: this.forceFit, - height: this.G2.DomUtil.getHeight(this.$refs.chart), - padding: this.padding - }) + this.creatChart() this.chart.source(this.data) this.chart.scale('sales', { tickInterval: 20 diff --git a/src/components/G2/charts/Line/1.vue b/src/components/G2/charts/Line/1.vue index 6ea337a6..1596f040 100644 --- a/src/components/G2/charts/Line/1.vue +++ b/src/components/G2/charts/Line/1.vue @@ -19,12 +19,7 @@ export default { methods: { // 初始化图表 initHandler () { - this.chart = new this.G2.Chart({ - container: this.$refs.chart, - forceFit: this.forceFit, - height: this.G2.DomUtil.getHeight(this.$refs.chart), - padding: this.padding - }) + this.creatChart() this.chart.source(this.data) this.chart.scale('value', { min: 0 diff --git a/src/components/G2/charts/Pie/1.vue b/src/components/G2/charts/Pie/1.vue index be97aa04..1634b689 100644 --- a/src/components/G2/charts/Pie/1.vue +++ b/src/components/G2/charts/Pie/1.vue @@ -29,12 +29,7 @@ export default { }, // 初始化图表 initHandler () { - this.chart = new this.G2.Chart({ - container: this.$refs.chart, - forceFit: this.forceFit, - height: this.G2.DomUtil.getHeight(this.$refs.chart), - padding: this.padding - }) + this.creatChart() this.chart.source(this.dvMaker(), { percent: { formatter: val => { diff --git a/src/components/G2/mixins/G2.js b/src/components/G2/mixins/G2.js index d1f9f0c7..cbbf38ae 100644 --- a/src/components/G2/mixins/G2.js +++ b/src/components/G2/mixins/G2.js @@ -59,6 +59,15 @@ export default { } }, methods: { + // 创建图表对象 + creatChart () { + this.chart = new this.G2.Chart({ + container: this.$refs.chart, + forceFit: this.forceFit, + height: this.G2.DomUtil.getHeight(this.$refs.chart), + padding: this.padding + }) + }, // 重绘大小 resize (width, height) { if (this.chart) { diff --git a/src/mock/chart/G2Column.js b/src/mock/chart/G2Column.js index 8bb4007d..bff9c145 100644 --- a/src/mock/chart/G2Column.js +++ b/src/mock/chart/G2Column.js @@ -8,14 +8,12 @@ Mock.mock('/api/chart/G2Column', 'post', ({body, type, url}) => { code: 0, msg: '请求成功', data: [ - { year: '1951 年', sales: 38 }, - { year: '1952 年', sales: 52 }, - { year: '1956 年', sales: 61 }, - { year: '1957 年', sales: 145 }, - { year: '1958 年', sales: 48 }, - { year: '1959 年', sales: 38 }, - { year: '1960 年', sales: 38 }, - { year: '1962 年', sales: 38 } + { year: '1951', sales: 38 }, + { year: '1952', sales: 52 }, + { year: '1956', sales: 61 }, + { year: '1957', sales: 145 }, + { year: '1958', sales: 48 }, + { year: '1959', sales: 38 } ] } default: diff --git a/src/pages/demo/chart/index/mixins/layout.js b/src/pages/demo/chart/index/mixins/layout.js index dc873d85..12d5e68c 100644 --- a/src/pages/demo/chart/index/mixins/layout.js +++ b/src/pages/demo/chart/index/mixins/layout.js @@ -5,7 +5,7 @@ export default { layout: [ {'x': 0, 'y': 0, 'w': 8, 'h': 9, 'i': '0'}, {'x': 8, 'y': 0, 'w': 4, 'h': 9, 'i': '1'}, - {'x': 0, 'y': 9, 'w': 5, 'h': 7, 'i': '2'} + {'x': 0, 'y': 9, 'w': 4, 'h': 7, 'i': '2'} ], colNum: 12, rowHeight: 30,