echarts柱状图

在这里插入图片描述

<template>
	<div id="mainCH" style="width: 100%; height: 400px;"></div>
</template>

<script>
	let echarts = require('echarts/lib/echarts')
	// 引入柱状图组件
	require('echarts/lib/chart/bar')
	// 引入提示框和title组件
	require('echarts/lib/component/tooltip')
	require('echarts/lib/component/title')
	export default {
		props: {
			PaiKedu: { // 样式 - 1
				default () {
					return {}
				}
			},

			PaiNumber: { //标题文本 - 1
				default: ''
			},
		},
		data() {
			return {
				title: 'Hello',
				huodong: [],
				zong: [],
			}
		},
		watch: {
			PaiKedu: {
				immediate: true,
				handler: function(value) {
					this.huodong = value;
				}
			},
			PaiNumber: {
				immediate: true,
				handler: function(value) {
					this.zong = value;
				}
			},
			huodong: function() {
				if (this.huodong.length > 0) {
					this.drawBar()
				}
			}
		},
		mounted() {
			if (this.huodong.length > 0) {
				this.drawBar()
			}
		},
		methods: {
			drawBar() {
				let myChart = echarts.init(document.getElementById("mainCH"));
				var option = {
					grid: {
						x: 50,
						y: 20,
						x2: 30,
						y2: 130,
					},
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'shadow'
						},
						formatter: "{b}: {c}" // 这里是鼠标移上去的显示数据
					},
					xAxis: {
						splitLine: {
							show: false
						},
						//这里填写刻度值 [前端,软件,测试,后端,UI,安全]
						data: this.huodong,

						axisTick: {
							show: false
						},
						axisLine: {
							"show": true,
							lineStyle: {
								color: '#BFC8DE' //更改坐标轴颜色
							}
						},

						axisLabel: {
							show: true,
							textStyle: {
								color: '#333333', //更改坐标轴文字颜色
								fontSize: 12 //更改坐标轴文字大小
							},
							// 文字斜着
							rotate:45,
						},
					},
					yAxis: {
						splitLine: { //分割线
							show: true,
							lineStyle: {
								color: '#6076AD',
								width: 1,
								opacity: .5,
							}
						},
						axisLabel: {
							show: true,
							textStyle: {
								color: '#333333', //更改坐标轴文字颜色
								fontSize: 12 //更改坐标轴文字大小
							}
						},
						axisTick: {
							show: false
						},
						axisLine: {
							lineStyle: {
								color: '#5e97b5' //更改坐标轴颜色
							}
						}
					},
					series: [{
						
						type: 'bar',
						barWidth: 18,
						top: 0,
						bottom: 50,
						itemStyle: {
							normal: {
								color: function(params) {
									var colorList = [
										['#0181DE', '#67E0E3'],
										['#D789FF', '#E9BFFF'],
										['#0181DE', '#67E0E3'],
										['#D789FF', '#E9BFFF'],
										['#0181DE', '#67E0E3'],
										['#D789FF', '#E9BFFF'],
										['#0181DE', '#67E0E3'],
										['#D789FF', '#E9BFFF'],
										['#0181DE', '#67E0E3'],
										['#D789FF', '#E9BFFF'],
										['#0181DE', '#67E0E3'],
										['#D789FF', '#E9BFFF'],
									];
									var index = params.dataIndex;
									if (params.dataIndex >= colorList.length) {
										index = params.dataIndex - colorList.length;
									}
									return new echarts.graphic.LinearGradient(0, 1, 0, 0,
										[{
												offset: 0,
												color: colorList[index][0]
											},
											{
												offset: 1,
												color: colorList[index][1]
											}
										]);
								}
							}
						},
						//这里填写[1,2,5,4,8,6,2,1,4,5]
						data: this.zong
					}]
				};

				myChart.setOption(option);
			}
		}
	}
</script>

<style>
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值