Echarts的Y轴添加定值横线的示例

在这里插入图片描述

第010个

点击查看专栏目录



Echarts折线图的y轴要画一条横线,主要是在series中设置markLine的图表标线参数,具体的参考源代码。

示例效果

在这里插入图片描述

示例源代码(共142行)

/*
* @Author: 还是大剑师兰特(CSDN)
* @下面源代码版权归还是大剑师兰特所有,可供学习或商业项目中借鉴,未经授权,不得重复地发表到博客、论坛,问答,git等公共空间或网站中。
* @Email: 2909222303@qq.com
* @First published in CSDN
* @First published time: 2023-02-04
*/
<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);
				myChart.setOption({
					title: {
						text: '标题:ECharts示例'
					},
					xAxis: {
						type: 'category',
						data: ['cuclife', 'openlayers', 'cesium', 'echarts', 'leaflet']
					},
					yAxis: {
						type: 'value',
						name: '技术技能值', //坐标轴名称
						nameLocation: 'middle', //坐标轴的位置
						nameTextStyle: {
							color: '#ff00ff',
							//align:'left',
						},
						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: 'line',
						data: [15, 36, 10, 10, 20],
						itemStyle: {
							//静态时显示状态
							color: new echarts.graphic.LinearGradient(
								// (x1,y1) 点到点 (x2,y2) 之间进行渐变
								0, 0, 1, 0,
								[{
										offset: 0,
										color: '#ff00ff'
									}, // 0 起始颜色
									{
										offset: 0.5,
										color: '#ffff00'
									}, // 0 起始颜色
									{
										offset: 1,
										color: '#ff0000'
									} // 1 结束颜色
								]
							),
						},
						
						markLine : {
							 symbol: ['none','arrow'], //['none']表示是一条横线;['arrow', 'none']表示线的左边是箭头,右边没右箭头;['none','arrow']表示线的左边没有箭头,右边有箭头
							 label:{
								   position:"start" //将警示值放在哪个位置,三个值“start”,"middle","end" 开始 中点 结束
							 },
							 data : [{
								   silent:false, //鼠标悬停事件 true没有,false有
								   lineStyle:{ //警戒线的样式 ,虚实 颜色
										 type:"dotted", //样式  ‘solid’和'dotted'
										 color:"#FA3934",
										 width: 3   //宽度
									},
								   yAxis: 22 // 警戒线的标注值,可以有多个yAxis,多条警示线 或者采用 {type : 'average', name: '平均值'},type值有 max min average,分为最大,最小,平均值
							 }]
						}					
						
						
					}]
				});
			}
		},
		mounted() {
			this.initCharts();
			window.addEventListener("online", () => {
			console.log("网络连接成功");
			});
			window.addEventListener("offline", () => {
				console.log("网络连接失败");
			});
		}
	}
</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>

相关资料参考

https://echarts.apache.org/zh/option.html#series-line.markLine

专栏介绍

在vue和echarts联合技术栈的操控下,本专栏提供行之有效的源代码示例。这里既包括样式的修改,又包括常用bug的解决。
(1)提供title示例:展示控制标题的颜色、位置、子标题,连接等
(2)提供legend示例:展示控制图例的类型、宽度、高度、位置、间隙,边框、阴影、透明度、偏移,字体、颜色,提示语等
(3)提供grid示例:展示控制绘图网格的位置、宽度、高度、边框、阴影等
(4)提供xAxis示例:展示控制x 轴的位置、类型、名称、字体、对齐方式、边框、阴影、宽度、高度等
(5)提供yAxis示例:展示控制y 轴的位置、类型、名称、字体、对齐方式、边框、阴影、宽度、高度等
(6)提供dataZoom示例:展示控制区域缩放的类型、位置、filterMode等
(7)提供tooltip示例:展示控制提示框组件的触发方式、位置、样式,标签、动画、内容格式器等
(8)提供地理坐标系示例:展示控制地理坐标的经纬度、放缩、位置,距离、字体、边框等
(9)提供animation示例:展示控制动画的持续时间、延迟时间、动画方式,连接等
(10)提供其他示例:展示series等组件的信息内容。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

还是大剑师兰特

打赏一杯可口可乐

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

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

打赏作者

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

抵扣说明:

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

余额充值