Vue3Echarts通用的横向柱状图

Echarts通用的横向柱状图,根据月份分别统计网站与公众号的数量,两条柱状图很直观,以下是代码示例:

下载Echarts

//npm
npm install echarts --save
 
//淘宝镜像cnpm(安装速度快)
cnpm install echarts --save
 
//yarn
yarn add echarts

代码示例

<template>
    <div id="echartsFour" style="width: 100%;height: 100%;"></div>
</template>
 
<script setup>
    import * as echarts from 'echarts';
    import { onMounted,ref } from 'vue';
    onMounted(()=>{
        getEcharts();
    })
    const getEcharts = () => {
        let chartDom = document.getElementById("echartsFour");
        let myChart = echarts.init(chartDom);
        let dateArr = ["2023-01","2023-02","2023-03","2023-04","2023-05","2023-06"]
        let wzArr = [20,30,40,50,60,70]
      let gzhArr = [88,99,100,110,120,122]
      let option = {
            backgroundColor:"#010407",
      	grid: {
      		left: '12%',
      		right: '12%',
      		top: "12%",
      	},
      	legend: {
      		show: true,
      		// itemWidth:52,
      		// itemHeight:30,
      		// itemGap:50,
      		left: "center",
      		top: 10,
      		textStyle: {
      			color: '#fff',
      			fontSize: 16
      		}
      	},
      	"xAxis": {
      		type: 'value',
      		// "max": max,
      		"splitLine": {
      			"show": true,
      			lineStyle: {
      				color: "#232e32"
      			}
      		},
      		"axisLine": {
      			"show": false
      		},
      		"axisLabel": {
      			"show": true,
      			"textStyle": {
      				"color": "#fff",
      				"fontSize": 16
      			}
      		},
      		"axisTick": {
      			"show": false
      		}
      	},
      	"yAxis": [{
      		"type": "category",
      		"inverse": true,
      		"data": dateArr,
      		"axisLine": {
      			"show": false
      		},
      		"axisTick": {
      			"show": false
      		},
      		"axisLabel": {
      			// "margin": 10,
      			"textStyle": {
      				"color": "#fff",
      				"fontSize": 16
      			}
      		}
      	}],
      	"series": [{ //内
      			type: 'bar',
      			barWidth: 13,
      			barGap: 0.5,
      			name: '网站',
      			label: {
      				show: true,
      				position: 'right',
      				textStyle: {
      					color: '#fff',
      					fontSize: 16,
      					padding: [0, 10],
      					rich: {
      						a: {
      							color: '#fff',
      							fontSize: 36
      						}
      					}
      				}
      			},
      			legendHoverLink: false,
      			silent: true,
      			itemStyle: {
      				color: {
      					type: 'linear',
      					x: 0,
      					y: 0,
      					x2: 1,
      					y2: 0,
      					colorStops: [{
      						offset: 0,
      						color: '#0e3537' // 0% 处的颜色
      					}, {
      						offset: 1,
      						color: '#41e1ba' // 100% 处的颜色
      					}],
      					globalCoord: false // 缺省为 false
      				} //底色
      			},
      			data: wzArr
      		},
      		{ //内2
      			type: 'bar',
      			barWidth: 13,
      			name: '公众号',
      			legendHoverLink: false,
      			silent: true,
      			label: {
      				show: true,
      				position: 'right',
      				textStyle: {
      					color: '#fff',
      					padding: [0, 10],
      					fontSize: 16,
      					rich: {
      						a: {
      							color: '#fff',
      							fontSize: 36
      						}
      					}
      				}
      			},
      			itemStyle: {
      				color: {
      					type: 'linear',
      					x: 0,
      					y: 0,
      					x2: 1,
      					y2: 0,
      					colorStops: [{
      						offset: 0,
      						color: '#0a303e' // 0% 处的颜色
      					}, {
      						offset: 1,
      						color: '#21a8ea' // 100% 处的颜色
      					}],
      					globalCoord: false // 缺省为 false
      				} //底色
      			},
      			data: gzhArr
      		}
      	]
      };
        myChart.setOption(option);
    }
</script>

运行结果

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈琦鹏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值