File tree Expand file tree Collapse file tree
components/mpvue-echarts/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change 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 >
9393 export default {
9494 data () {
9595 return {
96- echarts: echarts,
96+ // echarts: echarts,
9797 updateStatus: false
9898 }
9999 },
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
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
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 }
You can’t perform that action at this time.
0 commit comments