首页 > 其他分享 >vue项目引入echarts柱状图

vue项目引入echarts柱状图

时间:2022-12-21 08:55:49浏览次数:42  
标签:vue color chart default 柱状图 offset type echarts

一。components文件下引入 barCharts.vue文件

<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
//import resize from './mixins/resize'

const animationDuration = 6000

export default {
  //mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '200px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器,坐标轴触发有效
            type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
          }
        },
        grid: {
          top: 30,
          left: '2%',
          right: '1%',
          bottom: 10,
          containLabel: true
        },
        dataset: {
          source: [
            ['product', '2015','2016'],
            ['AC06H', 143.3,60],
            ['AC06L', 83.1,21.4],
            ['AC12N', 386.4 ,35.3],
            ['AC125', 72.4 ,10],
            ['AC13E', 192.4 ,72],
            ['AC13W', 572.4 ,10],
            ['AC18H', 142.4 ,47],
          ]
        },
        xAxis: { type: 'category' },
        yAxis: {},
        series: [{ 
          type: 'bar',
          itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: '#09c9c5' },
            { offset: 1, color: '#003791' }
            ])
          }
        },{ 
          type: 'bar',
          itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: '#5eff4d' },
            { offset: 1, color: '#245119' }
          ])
        },
        }]
      })
    }
  }
}
</script>

二。需要的页面引入组件:

 

 

 

 效果图如下:

 

标签:vue,color,chart,default,柱状图,offset,type,echarts
From: https://www.cnblogs.com/anna001/p/16995487.html

相关文章

  • vue 项目引入 echarts折线图
    一。components文件下新建lineCharts.vue<template><div:class="className":style="{height:height,width:width}"/></template><script>import*asec......
  • vue3 Composition API使用
    Vue3新增了CompositionAPI。我们只需将实现某一功能的相关代码全部放进一个函数中,然后return需要对外暴露的对象。不同功能的代码都是一个个函数,最终在setup()函数中......
  • Vue 作用域插槽
    摘抄自:https://www.jianshu.com/p/0c9516a3be80  ......
  • Vue基础 · 组件的使用(4)
    组件将公用的功能抽离出来,形成组件;目的:复用代码。1.1全局组件<divid="app"><!--引用组件,可多次引用--><demo></demo></div><scriptsrc="../js/vue......
  • 前端工程化Vue-cli
    六前端工程化vue-cliVue是渐近式框架,你可以用它一个功能,也可以用全家桶。前面的章节中,我们是在html中引入vue.js,只用它核心的数据绑定功能。但基于vue的扩展还有很多,......
  • Vue 中的 Todo-list 案例
    Vue中的 Todo-list案例1:示例​​​​总结TodoList案例组件化编码流程:(1).拆分静态组件:组件要按照功能点拆分,命名不要与html元素冲突。(2).实现动态组件:考虑好数据的存......
  • vue.nextTick()方法的使用详解
    1,什么是Vue.nextTick()理解:nextTick(),是将回调函数延迟在下一次dom更新数据后调用,简单的理解是:当数据更新了,在dom中渲染后,自动执行该函数,1<template>2<divclass......
  • vue项目运行不起来的解决办法
    一、公司拉下来的代码和同事的node版本一样就是运行不起来项目解决方法:1、应该是老问题,原来的味道,原来的方法,直接删除node_modules这个文件夹【相当于依赖包......
  • 'vue-cli-service' 不是内部或外部命令,也不是可运行的程序或批处理文件
    'vue-cli-service'不是内部或外部命令,也不是可运行的程序或批处理文件 1、背景介绍在执行npmrunserve命令启动前端服务时,有报错提示。 2、解决方案执行如下......
  • vue去掉 ESlint 校验
    整个项目都关闭创建.eslintrc.js写入如下代码module.exports={"env":{"browser":true,"es6":true},"extends":"plugin:vue/essential"......