• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Vue结合Apache Echarts

武飞扬头像
哇塞大嘴好帅(DaZuiZui)
帮助3

Vue结合Apache Echarts

1.通过npm获取Apache Echarts

npm install echarts --save

2.在main.js引用Apache Echarts

import * as echarts from 'echarts';
Vue.use(echarts);

3.创建Dom

  <div id="myChart" style="width: 600px;height:400px;"></div>

4.创建表图里面的数据

var myChart = echarts.init(document.getElementById('myChart'));
    myChart.setOption({
 
   xAxis: {
      //如果绑定vue数据直接this.变量名就可以了
    data: [2018, 2019, 2020, 2021, this.tip]
  },
  yAxis: {},
        series: [
    {
      data: [10, 40, 28, 23, 40],
      type: 'line',
      areaStyle: {}
    },
    {
      data: [25, 39, 23, 35, 40],
      type: 'line',
      areaStyle: {
        color: '#ff0',
        opacity: 0.5
      }
    }
  ]
})
学新通

5.在特定的vue页面引用echarts

<script>
import * as echarts from 'echarts';
export default {	.......

6.初始化页面数据

6.1 方法A 在mounted初始化

  //自启动
  mounted()
	 var myChart = echarts.init(document.getElementById('myChart'));
    myChart.setOption({
 
   xAxis: {
    data: [2018, 2019, 2020, 2021, this.tip]
  },
  yAxis: {},
        series: [
    {
      data: [10, 40, 28, 23, 40],
      type: 'line',
      areaStyle: {}
    },
    {
      data: [25, 39, 23, 35, 40],
      type: 'line',
      areaStyle: {
        color: '#ff0',
        opacity: 0.5
      }
    }
  ]
     })
 
  },
学新通

6.2 方法B方法

  data () {
    return {
		 fileList: [],
		 t: null,
        option: {
			series: [
				{
				type: 'pie',
				data: [
					{
					value: 335,
					name: '直接访问'
					},
					{
					value: 234,
					name: '联盟广告'
					},
					{
					value: 1548,
					name: '搜索引擎'
					}
				]
				}
			]
		},
    }
  },
      
  //自启动
  mounted(){
	var myChart = echarts.init(document.getElementById('myChart'));
    myChart.setOption(this.option)
  },
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfckhje
系列文章
更多 icon
同类精品
更多 icon
继续加载