[小程序Echarts圖表組件使用 - 雲+社區 - 騰訊雲](https://cloud.tencent.com/developer/article/1450181)
1:下載 GitHub 上的 項目
https://github.com/ecomfe/echarts-for-weixin
2:但項目下載之后,打開小程序開發工具,可以看到效果如下,適配性還是比較完美的。
如果是在項目里面引入組件的話,打開從github上面下載的代碼,將ec-canvas文件夾復制黏貼到你的項目里面。
圖片.png
好的,組件已經復制到了我的項目里面,現在我想實現一個折線圖,現在開始去組件里面搬運復制黏貼代碼了。 wxml
<!--index.wxml--> <view class="container"> <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec }}"></ec-canvas> </view>
js
import * as echarts from '../../ec-canvas/echarts'; const app = getApp(); function initChart(canvas, width, height) { const chart = echarts.init(canvas, null, { width: width, height: height }); canvas.setChart(chart); var option = { title: { text: '測試下面legend的紅色區域不應被裁剪', left: 'center' }, color: ["#37A2DA", "#67E0E3", "#9FE6B8"], legend: { data: ['A', 'B', 'C'], top: 50, left: 'center', backgroundColor: 'red', z: 100 }, grid: { containLabel: true }, tooltip: { show: true, trigger: 'axis' }, xAxis: { type: 'category', boundaryGap: false, data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], // show: false }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } } // show: false }, series: [{ name: 'A', type: 'line', smooth: true, data: [18, 36, 65, 30, 78, 40, 33] }, { name: 'B', type: 'line', smooth: true, data: [12, 50, 51, 35, 70, 30, 20] }, { name: 'C', type: 'line', smooth: true, data: [10, 30, 31, 50, 40, 20, 10] }] }; chart.setOption(option); return chart; } Page({ onShareAppMessage