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
    评论
您好!对于使用 Vue 3 和 ECharts 创建柱状图,您可以按照以下步骤进行操作: 1. 首先,确保您已经安装了 Vue 3 和 ECharts。可以使用以下命令进行安装: ```bash npm install vue@next echarts ``` 2. 在 Vue 组件引入 ECharts 和其样式文件。可以在 `main.js` 或者需要使用柱状图的组件进行引入: ```javascript import { createApp } from 'vue'; import * as echarts from 'echarts'; import 'echarts/dist/echarts.min.css'; const app = createApp(App); app.config.globalProperties.$echarts = echarts; app.mount('#app'); ``` 3. 在需要显示柱状图的组件,创建一个容器来容纳图表,并引入 ECharts 的实例: ```html <template> <div class="chart-container"> <div ref="chart" style="width: 100%; height: 400px;"></div> </div> </template> <script> export default { mounted() { this.renderChart(); }, methods: { renderChart() { const chartDom = this.$refs.chart; const myChart = this.$echarts.init(chartDom); // 在这里使用 ECharts 的 API 绘制柱状图 // 例如: myChart.setOption({ title: { text: '柱状图示例' }, xAxis: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] }, yAxis: { type: 'value' }, series: [{ data: [10, 20, 30, 40, 50], type: 'bar' }] }); } } }; </script> <style scoped> .chart-container { width: 100%; height: 400px; } </style> ``` 以上是一个简单的示例,您可以根据您的需求进行进一步的配置和样式调整。希望对您有所帮助!如果您有任何问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值