vue 使用echarts画柱状图

安装模块: npm install --save echarts

全局注册 在main.js文件写入代码

// 引入echarts
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

单个页面使用

<template>
  <Page>
    <page-main>
      <div class="test-container">
        <div id="myChartBar"></div>
      </div>
    </page-main>
  </Page>
</template>

<script>
export default {
  name: 'Test',
  data () {
    return {
      myChartBar: null, // 折线图
      chartOptionBar: {
        legend: {
          show: false,
          left: 0,
          top: 0,
          itemWidth: 14,
          itemHeight: 14,
          textStyle: {
            color: '#000',
          },
        },
        tooltip: {
          trigger: 'item'
        },
        grid: {
          containLabel: true,
          top: 50,
          left: 10,
          right: 15,
          bottom: 15,
          width: 'auto', //图例宽度
        },
        xAxis: {
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
          // 坐标轴刻度
          axisTick: {
            show: false,
          },
          axisLine: {
            show: true, //
            lineStyle: {
              color: '#293843', // x轴线颜色
            },
          },
          axisLabel: {
            textStyle: {
              color: '#000',
            },
            align: 'center',
          },
        },
        yAxis: {
          type: 'value',
          splitLine: {
            lineStyle: {
              type: 'dashed',
              color: '#293843',
            },
          },
          axisLabel: {
            textStyle: {
              color: '#000',
            },
          },
        },
        series: [
          {
            name: '',
            data: [44540.57, 64038.35, 64263.82, 68963.54, 78932.06, 50969.39, 72784.71, 87979.53, 77678.91, 65348.56, 83008.5, 61542.54],
            color: '#208CFC',
            type: 'bar',
          },
        ],
      },
    };
  },
  methods: {

  },
  mounted() {
    this.myChartBar = this.$echarts.init(document.getElementById('myChartBar'));
    this.myChartBar.setOption(this.chartOptionBar);
  }
};
</script>

<style lang="scss" scoped>
  .test-container {
    padding: 20px;
    width: 700px;
    height: 500px;
    background: #fff;
    #myChartBar {
      width: 100%;
      height: 100%;
    }
  }
</style>

效果如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值