Skip to content

Commit 5bf37e5

Browse files
committed
update: echarts
1 parent 0fe0181 commit 5bf37e5

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

‎components/mpvue-echarts/src/echarts.vue‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,11 @@ export default {
4747
},
4848
// #ifdef H5
4949
mounted() {
50-
if (!this.echarts) {
51-
console.warn('组件需绑定 echarts 变量,例:<ec-canvas id="mychart-dom-bar" '
52-
+ 'canvas-id="mychart-bar" :echarts="echarts"></ec-canvas>');
53-
return;
54-
}
55-
5650
if (!this.lazyLoad) this.init();
5751
},
5852
// #endif
5953
// #ifndef H5
6054
onReady() {
61-
if (!this.echarts) {
62-
console.warn('组件需绑定 echarts 变量,例:<ec-canvas id="mychart-dom-bar" '
63-
+ 'canvas-id="mychart-bar" :echarts="echarts"></ec-canvas>');
64-
return;
65-
}
66-
6755
if (!this.lazyLoad) this.init();
6856
},
6957
// #endif
@@ -75,13 +63,11 @@ export default {
7563
}
7664
7765
const { canvasId } = this;
78-
this.ctx = wx.createCanvasContext(canvasId);
66+
this.ctx = wx.createCanvasContext(canvasId, this);
7967
8068
const canvas = new WxCanvas(this.ctx, canvasId);
8169
82-
this.echarts.setCanvasCreator(() => canvas);
83-
84-
const query = wx.createSelectorQuery();
70+
const query = wx.createSelectorQuery().in(this);
8571
query.select(`#${canvasId}`).boundingClientRect((res) => {
8672
if (!res) {
8773
setTimeout(() => this.init(), 50);

‎pages/template/echarts/echarts.vue‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<view class="title">饼图示例</view>
1212
<button class="update-btn" type="primary" size="mini" @click="updatePie">修改饼状图数据</button>
1313
</view>
14-
<mpvue-echarts :echarts="echarts" :onInit="pieInit" canvasId="pie" ref="pieChart" />
14+
<mpvue-echarts class="ec-canvas" :onInit="pieInit" canvasId="pie" ref="pieChart" />
1515
</view>
1616
<view class="canvasView">
1717
<view class="title">折线图示例</view>
18-
<mpvue-echarts :echarts="echarts" :onInit="lineInit" canvasId="line" ref="lineChart" />
18+
<mpvue-echarts class="ec-canvas" :onInit="lineInit" canvasId="line" ref="lineChart" />
1919
</view>
2020
</view>
2121
</template>
@@ -93,7 +93,7 @@
9393
export default {
9494
data() {
9595
return {
96-
echarts: echarts,
96+
// echarts: echarts,
9797
updateStatus: false
9898
}
9999
},
@@ -131,6 +131,7 @@
131131
this.updateStatus = true;
132132
},
133133
pieInit(canvas, width, height) {
134+
echarts.setCanvasCreator(() => canvas);
134135
let pieChart = echarts.init(canvas, null, {
135136
width: width,
136137
height: height
@@ -141,6 +142,7 @@
141142
return pieChart
142143
},
143144
lineInit(canvas, width, height) {
145+
echarts.setCanvasCreator(() => canvas);
144146
let lineChart = echarts.init(canvas, null, {
145147
width: width,
146148
height: height
@@ -188,6 +190,12 @@
188190
flex-direction: column;
189191
}
190192
193+
.ec-canvas {
194+
width: 100%;
195+
height: 100%;
196+
flex: 1;
197+
}
198+
191199
.navigate {
192200
color: #007AFF;
193201
}

0 commit comments

Comments
 (0)