Vue中echart柱状图使用方法和常用属性

使用方法

1.安装

npm install echarts --save

2.main.js 中引入

import Element from 'element-ui'
import './assets/styles/element-variables.scss'
Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

 3.在页面中引入

import * as echarts from "echarts";

4.使用

html:

<div
          class="echart"
          id="activePopulation"
          :style="activePopulationStyle"
        ></div>

data:

activePopulationStyle: {
        width: "95%",
        height: "95%",
        backgroundColor: "white",
      }, //图表样式

mounted:

  mounted() {
          const option = {
        title: {
          text: "登录用户人次统计",//主标题
          subtext:
            "登录用户数据说明:指用户访问的人次数量汇总",//副标题
          x: "center",//标题在x轴的对齐方式
          y: "top",//标题在y轴的对齐方式
          textStyle: {
            color: "#000000",//文字颜色
            fontStyle: "normal", //字体风格,'normal','italic','oblique'
            fontWeight: "400",//字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
            fontFamily:'sans-serif',//字体系列
            fontSize: 16,//字体大小
          },
        },
        grid: {
          y2: 150, //增加柱形图纵向的高度,用于横轴信息全部显示
        },
        xAxis: [
          {
            type: "category",
            data: this.content,//横轴的数据
            axisLabel: {
              interval: 0, //横轴信息全部显示
              rotate: 45, //-15度角倾斜显示
            },
          },
        ],
        yAxis: {},
        legend: {
          data: ["登录次数"], // 需要跟series中的name对应否则不显示.
          x: "center",//色块在x轴的对齐方式
          y: "bottom",//色块在y轴的对齐方式
          textStyle: {
            fontSize: 15, // 设置文字大小
            color: "#718ca2", // 文字颜色
            borderRadius: 6, // 色块的圆角
          },
          left: "center", // 调整整体在图表中的对其方式
          itemWidth: 15, // 设置色块宽度
          itemHeight: 15, // 设置色块高度
        },
        series: [
          {
            name: "登录次数",
            type: "bar", //形状为柱状图
            data: this.days,//柱状图数据
            barWidth: 10, //设置柱子的宽度
          },
        ],
      };
      const activePopulation = echarts.init(
        document.getElementById("activePopulation")
      );
      activePopulation.setOption(option);
      //随着屏幕大小调节图表
      window.addEventListener("resize", () => {
        activePopulation.resize();
      });
  },

常用属性

1.设置柱状图的标题

2.调整x轴的标题全部显示

3.调整色块和柱状的大小

  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值