Vue渐变圆边柱状图

文章展示了如何在Vue项目中通过Echarts库创建一个具有渐变圆边效果的柱状图。代码示例包括模板、脚本部分,详细配置了图表的样式,如颜色渐变、边角圆润等。

通过引入Echarts来实现渐变圆边柱状图效果,话不多说直接上样式代码!

实现效果:

代码:

<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: '320px'
			}
		},
		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: '5%',
						left: '5%',
						right: '3%',
						bottom: '5%',
						containLabel: true
					},
					xAxis: [{
						type: 'category',
						data: ['1号实验室', '2号实验室', '3号实验室', '4号实验室', '5号实验室', '6号实验室'],
						axisTick: {
							show: false,
						},
						axisLine: {
							show: false,
							lineStyle: {
								color: '#000000',
							}
						},
					}],
					yAxis: [{
						type: 'value',
						axisTick: {
							show: false
						},
						axisLine: {
							lineStyle: {
								color: '#000000',
							}
						},
					}],
					series: [{
						name: '当前平均湿度(%RH):',
						type: 'bar',
						stack: 'vistors',
						barWidth: '20%',
						itemStyle: {
							//柱形图圆角,初始化效果
							borderRadius: [15, 15, 15, 15],
							color: new echarts.graphic.LinearGradient(
								0, 1, 0, 0, [{ //只要修改前四个参数就ok
										offset: 0,
										color: '#45d0cb'
									}, //柱图渐变色
									{
										offset: 1,
										color: '#1d8ff0'
									}
								]
							),
						},
						data: [69, 52, 20, 34, 62, 33],
						animationDuration
					}]
				})
			}
		}
	}
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

半度纳

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

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

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

打赏作者

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

抵扣说明:

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

余额充值