关于Echarts

安装Echart

nnpm install echarts --save 
复制代码

1.引入Echarts

1.全局引入Echarts(入口文件main.js),且将实例挂载到vue上

import echarts from 'echarts'
Vue.prototype.$echarts = echarts
复制代码

2.在组件中使用Echarts

<!--先引入Echarts-->
import echarts from 'echarts'
<!--定义图表信息 在data中定义,也可以外部定义,再引入-->
charts4: {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        <!--定义图表大小-->
        grid: {
          left: '10%',
          right: '4%',
          bottom: '-1%',
          containLabel: true
        },
        <!--X轴-->
        xAxis: {
          type: 'value',
          <!--为false,则不显示X轴坐标系 如果X轴有文字,则会都隐藏-->
          show: false
        },
        <!--Y轴-->
        yAxis: {
          type: 'category',
          <!--Y轴显示的数据-->
          data: ['南京', '长沙', '成都', '济南', '杭州', '合肥', '深州', '北京', '广州', '上海'],
          <!--轴线设置-->
          axisLine: {
            lineStyle: {
              color: '#0c78d7'
            },
            show: false
          },
          <!--轴坐标设置-->
          axisLabel: {
          <!--文字设置-->
            textStyle: {
              fontSize: '10'
            }
          },
          <!--坐标轴设置-->
          axisTick: {
            show: false
          }
        },
        <!--图表数据的一系列设置-->
        series: [
          {
            type: 'bar',
            data: [60, 70, 55, 65, 70, 75, 60, 80, 95, 100],
            itemStyle: {
              normal: {
                <!--设置颜色渐变-->
                color: new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
                  offset: 1,
                  color: '#1db7fc'
                }, {
                  offset: 0.5,
                  color: '#039de3'
                }, {
                  offset: 0,
                  color: '#02587f'
                }]),
                shadowColor: 'rgba(0, 0, 0, 0.4)'
              }
            },
            <!--braGap用于设置同一个类目内的柱形之间的间距,而barCategoryGap则用于设置不同类目之间的间距-->
            barCategoryGap: '50%'
          }
        ]
      }
复制代码

3.Echart自适应(写在mounted当中)

<!--Echarts初始化, 其中this.$refs.xl是获取的dom元素-->
var myChart0 = this.$echarts.init(this.$refs.xl)
<!--执行Echarts方法-->
myChart0.setOption(this.charts0)
<!--监听图表的变化-->
window.addEventListener('resize', function () {
  myChart0.resize()
})
复制代码

转载于:https://juejin.im/post/5c775804f265da2d8e70f9c4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值