diff --git a/src/components/charts/G2/components/Line/base.vue b/src/components/charts/G2/components/Line/base.vue
index 62162778..3dd8206e 100644
--- a/src/components/charts/G2/components/Line/base.vue
+++ b/src/components/charts/G2/components/Line/base.vue
@@ -38,9 +38,11 @@ export default {
changeData () {
if (this.chart) {
// 已经初始化过图表 更新数据
+ this.$log('changeData', '已经初始化过图表 只更新数据')
this.chart.changeData(this.data)
} else {
// 没有图表 新创建一个实例
+ this.$log('changeData', '没有图表 新创建一个实例')
this.init()
}
}
diff --git a/src/mock/chart/G2Line.js b/src/mock/chart/G2Line.js
index 7f081832..8a82ec63 100644
--- a/src/mock/chart/G2Line.js
+++ b/src/mock/chart/G2Line.js
@@ -1,23 +1,35 @@
import Mock from 'mockjs'
+const r = (add = 0) => {
+ return Math.round(Math.random() * 100) + add
+}
+
Mock.mock('/api/chart/G2Line', 'post', ({body, type, url}) => {
const _body = JSON.parse(body)
switch (_body.code) {
case 1:
+ let lastValue = 0
+ const temp = [
+ { year: '1991', value: 0 },
+ { year: '1992', value: 0 },
+ { year: '1993', value: 0 },
+ { year: '1994', value: 0 },
+ { year: '1995', value: 0 },
+ { year: '1996', value: 0 },
+ { year: '1997', value: 0 },
+ { year: '1998', value: 0 },
+ { year: '1999', value: 0 }
+ ]
+ const data = temp.map(e => {
+ e.value = lastValue + r()
+ lastValue = e.value
+ return e
+ })
+ lastValue = 0
return {
code: 0,
msg: '请求成功',
- data: [
- { year: '1991', value: 3 },
- { year: '1992', value: 4 },
- { year: '1993', value: 3.5 },
- { year: '1994', value: 5 },
- { year: '1995', value: 4.9 },
- { year: '1996', value: 6 },
- { year: '1997', value: 7 },
- { year: '1998', value: 9 },
- { year: '1999', value: 13 }
- ]
+ data
}
default:
return {}
diff --git a/src/mock/index.js b/src/mock/index.js
index f6694223..b8a70646 100644
--- a/src/mock/index.js
+++ b/src/mock/index.js
@@ -8,5 +8,5 @@ import '@/mock/chart'
// 设置全局延时 没有延时的话有时候会检测不到数据变化 建议保留
Mock.setup({
- timeout: '600-1000'
+ timeout: '300-600'
})
diff --git a/src/pages/demo/chart/index/components/ChartCardHeader.vue b/src/pages/demo/chart/index/components/ChartCardHeader.vue
new file mode 100644
index 00000000..9b13f8df
--- /dev/null
+++ b/src/pages/demo/chart/index/components/ChartCardHeader.vue
@@ -0,0 +1,30 @@
+
+
+ {{title}}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/demo/chart/index/index.vue b/src/pages/demo/chart/index/index.vue
index 2cf2cf81..f8834c31 100644
--- a/src/pages/demo/chart/index/index.vue
+++ b/src/pages/demo/chart/index/index.vue
@@ -6,7 +6,10 @@
@resize="handleResize('G2LineBase1')"
@resized="handleResized('G2LineBase1')">
@@ -17,11 +20,15 @@
diff --git a/src/pages/demo/chart/index/mixins/layout.js b/src/pages/demo/chart/index/mixins/layout.js
index 1e938522..c68a03dc 100644
--- a/src/pages/demo/chart/index/mixins/layout.js
+++ b/src/pages/demo/chart/index/mixins/layout.js
@@ -22,7 +22,9 @@ export default {
methods: {
// 更新指定的图表
chartResize (name) {
- this.$refs[name].resize()
+ this.$nextTick(() => {
+ this.$refs[name].resize()
+ })
},
// 布局组件发生变化
layoutUpdatedHandler (newLayout) {