uniapp引用echarts的方法:1、透過uni-app官網直接安裝echarts插件產生echarts專案模板;2、創建一個新的hello uni-app專案模板;3、把echarts放到components中。
本教學操作環境:windows7系統、uni-app2.5.1版本,Dell G3電腦。
推薦(免費):uni-app教學
uni-app 介紹echarts
<template> <view class="container"> <view> <view class="canvasView"> <mpvue-echarts class="ec-canvas" @onInit="lineInit" canvasId="line" ref="lineChart" /> </view> </view> </view> </template> <script> // import * as echarts from '@/components/echarts/echarts.simple.min.js'; // import mpvueEcharts from '@/components/mpvue-echarts/src/echarts.vue'; import * as echarts from '../echarts/echarts.simple.min.js' import mpvueEcharts from '../mpvue-echarts/src/echarts.vue' export default { data() { return { updateStatus: false, line: { legend: { data: ['邮件营销'] }, xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value', data: [] }, dataZoom: [{ type: 'slider', start: 30, end: 100, zoomLock: false, }], grid: { left: 40, right: 40, bottom: 20, top: 40, containLabel: true }, series: [{ data: [], data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line', color: ['#5eb4e2'], //折线条的颜色 }] } } }, methods: { lineInit(e) { let { width, height } = e; let canvas = this.$refs.lineChart.canvas echarts.setCanvasCreator(() => canvas); let lineChart = echarts.init(canvas, null, { width: width, height: height }) canvas.setChart(lineChart) lineChart.setOption(this.line) this.$refs.lineChart.setChart(lineChart) }, }, components: { mpvueEcharts } } </script> <style> .ec-canvas { display: flex; height: 100%; flex: 1; } .canvasView { width: 700upx; height: 500upx; } </style>
1、透過uni- app 官網直接安裝echarts 外掛程式產生echarts專案範本
#2、在Hbuilder中建立一個新的hello uni-app專案範本
3、把echarts範本中components 下面的echarts 放到自己專案components 中
4、把hello uni-app模板中components 下面的mpvue-echarts 放到自己專案components 中
以上是uniapp中如何引用echarts的詳細內容。更多資訊請關注PHP中文網其他相關文章!