1.项目安装echarts
npm install echarts --save
2.全局配置:main.js
import echarts from 'echarts'
Vue.use(echarts)
Vue.prototype.$echarts = echarts
3.目标界面使用
<template>
2 <div>
3 <div class="total-class" id="myChart" :style="{width: '100%', height: '400px'}"></div>
4 </div>
5 </template>
6 <script>
7 export default {
8 data () {
9 return {
10 }
11 },
12 methods: {
13 drawLine () {
14 // 基于准备好的dom,初始化echarts实例
15 let myChart = this.$echarts.init(
16 document.getElementById('myChart')
17 )
18 // 绘制图表
19 myChart.setOption({
20 color: ['#3398DB'],
21 tooltip: {
22 trigger: 'axis',
23 axisPointer: { // 坐标轴指示器,坐标轴触发有效
24 type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
25 }
26 },
27 grid: {
28 left: '3%',
29 right: '4%',
30 bottom: '3%',
31 containLabel: true
32 },
33 xAxis: [
34 {
35 type: 'category',
36 data: ['Mon','Tue','Wed','Thur','Fir','Sat','Sun],
37 axisTick: {
38 alignWithLabel: true
39 }
40 }
41 ],
42 yAxis: [
43 {
44 type: 'value'
45 }
46 ],
47 series: [
48 {
49 name: '测试',
50 type: 'bar',
51 barWidth: '50%',
52 data: [15,35,45,68,70,50,60]53 }
54 ]
55 })
56 }
57 }
58 </script>


被折叠的 条评论
为什么被折叠?



