Echarts 每个柱子一种渐变色的象形柱状图-灵析社区

JACKY

本示例是解决每个柱状图的每一个柱子都呈现一种渐变色,每个柱子的颜色都不同。这里同时采用了象形的柱状图效果。

示例效果

示例源代码(共125行)

/*
* @Author: 还是大剑师兰特(CSDN)
* @下面源代码版权归还是大剑师兰特所有,可供学习或商业项目中借鉴,未经授权,不得重复地发表到博客、论坛,问答,git等公共空间或网站中。
* @Email: 2909222303@qq.com
* @First published in CSDN
* @First published time: 2023-02-27
*/
<template>
	<div class="container">
		<h3>vue+echarts:每个柱子一种渐变色的象形柱状图</h3>
		<p>大剑师兰特,还是大剑师兰特</p>
		<div id="vue-echarts" ref="refEcharts"> </div>
	</div>
</template>

<script>
	import * as echarts from 'echarts'; //局部引用,如果采用全局模式,这里不写
	export default {
		name: 'cuclife',
		data() {
			return {}
		},
		methods: {
			initCharts() {
				let myChart = echarts.init(this.$refs.refEcharts);
				let colorList = {
					first: ["#F179C4", "#26AEFB", "#CDAD92", "#ED65BA", "#989FBB",  "#6718CF"],
					second: [ "#056FAB", "#FFAA62", "#E33AA3", "#28B1FF", "#FFAA62", "#F47384"]
				}

				myChart.setOption({
					title: {
						text: '标题:ECharts示例'
					},
					xAxis: {
						type: 'category',
						data: ['cuclife', 'openlayers', 'cesium', 'echarts', 'leaflet']
					},
					yAxis: {
						type: 'value',
						name: '技术技能值', //坐标轴名称
						nameLocation: 'middle', //坐标轴的位置
						nameTextStyle: {
							color: '#ff00ff',
						},
						nameGap: 50, //坐标轴名称与轴线之间的距离
						nameRotate: 90, //坐标轴名字旋转角度值,
						axisLine: {
							lineStyle: {
								color: '#ff00ff'
							},
							symbol: ['none', 'arrow'], //轴线两边的箭头
							symbolSize: [8, 12]
						},
						axisTick: {
							inside: false, //标轴刻度是否朝内,默认朝外
						},
						axisLabel: {
							show: true,
							inside: false,
							formatter: '{value}'
						},
						splitArea: {
							show: true,
							color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)'],
						}
					},
					grid: {
						x: 25,
						y: 55,
						x2: 25,
						y2: 20,
						containLabel: true
					},

					series: [{
                        // 以下是核心代码
						type: 'pictorialBar', //设置类型为象形柱状图
						symbol: 'rect', //图形类型,带圆角的矩形
						symbolMargin: '3', //图形垂直间隔
						symbolRepeat: true, //图形是否重复
						symbolSize: [50, 25], //图形元素的尺寸	
							
						itemStyle: {
							color: params => { //图形渐变颜色方法,四个数字分别代表,右,下,左,上,offset表示0%到100%
								return new echarts.graphic.LinearGradient(
									1, 0, 0, 0, [{
											offset: 0,
											color: colorList.first[params.dataIndex]
										},
										{
											offset: 1,
											color: colorList.second[params.dataIndex]
										}
									])
							}

						},
				
						data: [15, 36, 10, 10, 20],

					}]
				});
			}
		},
		mounted() {
			this.initCharts();
		}
	}
</script>
<style scoped>
	.container {
		width: 840px;
		height: 580px;
		margin: 50px auto 0;
		border: 1px solid rgb(228, 57, 97);
	}

	#vue-echarts {
		width: 800px;
		height: 460px;
		border: 1px solid #d8d;
		margin: 0 auto;
	}
</style>


阅读量:545

点赞量:0

收藏量:0