enmnm...通常會使用npm下載echarts這個包,可是不知道是我本身的配置問題仍是別的緣由,一直出不來圖線,vue
因而,把Hello uni-app模板裏的那個組件抱過來,而後,成了!npm
首先,canvas
一、頁面引入app
<template> <view class="container"> <view> <view class="canvasView"> <mpvue-echarts class="ec-canvas" @onInit="lineInit" canvasId="line" ref="lineChart" /> </view> </view> </view> </template>
二、邏輯層echarts
<script> import * as echarts from '@/components/echarts/echarts.simple.min.js'; import mpvueEcharts from '@/components/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>
三、樣式設定ide
<style> .ec-canvas { display: flex; height: 100%; flex: 1; } .canvasView { width: 700upx; height: 500upx; } </style>