vue中使用echart图表



1、安装echarts依赖

//方法一
npm install echarts -S
//方法二  或者使用淘宝镜像安装
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install echarts -S

2、创建图表全局引入

// 引入echarts   main.js
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

3、页面结构

//  xx.vue
<div id="myChart" :style="{width: '300px', height: '300px'}"></div>

//
//
//
export default {
        name: "asset",
        mounted(){
          this.drawLine();
        },
        methods: {
          drawLine() {
            // 基于准备好的dom,初始化echarts实例
            let myChart = this.$echarts.init(document.getElementById('myChart'))
            // 绘制图表
            myChart.setOption({
              title: {text: ''},
              tooltip: {},
              xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['2018/12/04', '2018/12/05', '2018/12/06', '2018/12/07', '2018/12/08', '2018/12/09', '2018/12/10','2018/12/11','2018/12/12']
              },
              yAxis: {
                type: 'value'
              },
              series: [{
                data: [20000, 30000, 50000, 70000, 60000 ,100000, 130000, 140000,170000],
                type: 'line',
                itemStyle: {
                  color: 'rgb(24, 143, 244)'
                },
                areaStyle: {    // 颜色渐变
                  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{    //$echart 在main.js里面已经写到了
                    offset: 0,
                    color: 'rgb(24, 143, 244)'
                  }, {
                    offset: 1,
                    color: 'rgb(207, 232, 253)'
                  }])
                },
              }]
            });
            }
          },
         }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值