echarts多條折線圖添加單位


<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>w3cschool (www.w3cschool.cn) </title>
		<!-- 引入 echarts.js -->
		<script src="https://cdn.bootcdn.net/ajax/libs/echarts/4.8.0/echarts-en.common.js" rel="external nofollow">
		</script>
	</head>
	<body>
		<!-- 為ECharts准備一個具備大小(寬高)的Dom -->
		<div id="main" style="width: 600px;height:400px;"></div>
		<script type="text/javascript">
			// 基於准備好的dom,初始化echarts實例
			var myChart = echarts.init(document.getElementById('main'));
			// 指定圖表的配置項和數據
			var option = {

				title: {
					text: '堆疊區域圖'
				},
				tooltip: {
					trigger: 'axis',
					formatter: function(c) {
						console.log( c )
						let str = '';
						let temp  = {
							bgcricle:'',//顏色
							seriesName:"", //學校名
							valueData:'',//數值
							spacespan:'',
						};
						c.forEach((item) => {
							// 做的事情
							temp.bgcricle=item.marker;
							temp.seriesName=item.seriesName;
							temp.valueData=item.value+"個";
							temp.spacespan='<span style="display:inline-block;width:10px;height:10px;"></span>';
							str+=temp.bgcricle+temp.seriesName+temp.spacespan+temp.valueData+'<br />'
						})
						return str
					}
				},
				legend: {
					data: ['郵件營銷', '聯盟廣告', '視頻廣告']
				},
				toolbox: {
					feature: {
						saveAsImage: {}
					}
				},
				grid: {
					left: '3%',
					right: '4%',
					bottom: '3%',
					containLabel: true
				},
				xAxis: [{
					type: 'category',
					boundaryGap: false,
					data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
				}],
				yAxis: [{
					type: 'value'
				}],
				series: [{
						name: '郵件營銷',
						type: 'line',
						areaStyle: {},
						data: [120, 132, 101, 134, 90, 230, 210]
					},
					{
						name: '聯盟廣告',
						type: 'line',
						areaStyle: {},
						data: [220, 182, 191, 234, 290, 330, 310]
					},
					{
						name: '視頻廣告',
						type: 'line',
						areaStyle: {},
						data: [150, 232, 201, 154, 190, 330, 410]
					}
				]
			};


			// 使用剛指定的配置項和數據顯示圖表。
			myChart.setOption(option);
		</script>
	</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM