最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery使用echarts循環(huán)插入圖表實(shí)現(xiàn)過(guò)程

 更新時(shí)間:2025年05月28日 14:31:03   作者:Hero_rong  
這篇文章主要介紹了jQuery使用echarts循環(huán)插入圖表,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

jQuery使用echarts循環(huán)插入圖表

jQuery動(dòng)態(tài)循環(huán)插入echarts圖表

  • .center_img_list 是我們循環(huán)數(shù)據(jù)的地方
					<div class="center_img shadow">
						<div class="center_img_border">
							<div class="center_img_list">
								<div class="canvas"></div>
								<div class="img_title">一站式 HarmonyOS/OpenHarmo…</div>
								<div class="label">計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷</div>
							</div>
						</div>
					</div>
  • css:
			.center_img_border {
				display: flex;
				justify-content: space-around;
				padding: 0.3rem;
			}

			.center_img_list {
				width: 30%;
			}

			.center_img_list .canvas {
				border: solid green 1px;
				border-radius: 10px;
				width: 100%;
				height: 206px;
			}
  • js:
		var newList = [{
				"id": "1",
				"title": "計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷",
				"content": "圖表 1:雙十一美妝銷量",
				'list': [1, 20, 200, 3, 52, 99],
				'time': ['2023/01/02', '2023/01/03', '2023/02/02', '2023/02/22', '2023/03/02', '2023/04/02', ]
			},
			{
				"id": "2",
				"title": "計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷",
				"content": "圖表 2:雙十一家電銷量",
				'list': [1000, 20, 200, 3, 52, 99],
				'time': ['2023/01/02', '2023/01/03', '2023/02/02', '2023/02/22', '2023/03/02', '2023/04/02', ]
			},
			{
				"id": "3",
				"title": "計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷",
				"content": "圖表 3:雙十一家具銷量",
				'list': [100, 200, 220, 300, 2, 9],
				'time': ['2023/01/02', '2023/01/03', '2023/02/02', '2023/02/22', '2023/03/02', '2023/04/02', ]
			},
		]
		this.getEcharts(newList);
		// 圖表數(shù)據(jù)
		function getEcharts(newList) {
			let echartsHtml = ''
			$.each(newList, function(i, v) {
				echartsHtml += `<div class="center_img_list">
								<div class="canvas" id="canvas` + i + `" ></div>
								<div class="img_title">${v.content}</div>
								<div class="label">${v.title}</div>
							</div>`
				$(document).ready(function() {
					changeECharts(v.list, v.time, 'canvas' + i);
				})
			})
			$(".center_img_border").html(echartsHtml);
		}

		function changeECharts(changePCTRYsList, x, idname) {
			var chartDom = document.getElementById(idname);
			let objDom = {}
			objDom[idname] = echarts.init(chartDom);
			let option = {
				xAxis: [{
					type: 'category',
					boundaryGap: true,
					data: x,
					axisLabel: {
						interval: x.length - 2,
						fontSize: 12,
					},
					axisLine: {
						show: false, //隱藏x軸
					},
					axisTick: {
						show: false, //刻度線
					},
				}],
				grid: {
					left: '',
					right: 30,
					bottom: 20,
					top: 20,
					containLabel: true
				},
				tooltip: {
					show: true,
					trigger: 'axis'
				},
				yAxis: {
					show: true,
					scale: true,
					alignTicks: true,
					axisTick: {
						inside: true
					},
					type: 'value',
					min: Math.min(...changePCTRYsList),
					max: Math.max(...changePCTRYsList)
				},
				series: [{
						name: '收盤(pán)價(jià)',
						data: changePCTRYsList,
						type: 'line',
						itemStyle: {
							color: '#649E92',
						},
						symbol: 'none',
					},
					{
						name: '成交量',
						data: changePCTRYsList,
						type: 'line',
						itemStyle: {
							color: '#649E92',
						},
						symbol: 'none',
					}
				]
			};
			objDom[idname].setOption(option);
		}

y軸顯示最大值和最小值

y軸設(shè)置刻度最大和最小值

min: Math.min(...changePCTRYsList),
max: Math.max(...changePCTRYsList)

x軸只顯示兩個(gè)值,開(kāi)始日期和結(jié)束日期

在xAxis中的axisLabel設(shè)置 interval: x.length - 2 即可

					axisLabel: {
						interval: x.length - 2,
						fontSize: 12,
					},

全部代碼,可以直接運(yùn)行

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>echarts</title>
		<style>
			*,
			html,
			body {
				padding: 0;
				margin: 0;
				box-sizing: border-box;
			}

			.center_img_border {
				display: flex;
				justify-content: space-around;
				padding: 0.3rem;
			}

			.center_img_list {
				width: 30%;
			}

			.center_img_list .canvas {
				border: solid green 1px;
				border-radius: 10px;
				width: 100%;
				height: 206px;
			}
		</style>
	</head>

	<body>
		<div class="center_img_border">
			<div class="center_img_list">
				<div class="canvas"></div>
				<div class="img_title">一站式 HarmonyOS/OpenHarmo…</div>
				<div class="label">計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷</div>
			</div>
		</div>

	</body>
	<script type="text/javascript" src="js/echarts.js"></script>
	<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
	<script>
		var newList = [{
				"id": "1",
				"title": "計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷",
				"content": "圖表 1:雙十一美妝銷量",
				'list': [1, 20, 200, 3, 52, 99],
				'time': ['2023/01/02', '2023/01/03', '2023/02/02', '2023/02/22', '2023/03/02', '2023/04/02', ]
			},
			{
				"id": "2",
				"title": "計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷",
				"content": "圖表 2:雙十一家電銷量",
				'list': [1000, 20, 200, 3, 52, 99],
				'time': ['2023/01/02', '2023/01/03', '2023/02/02', '2023/02/22', '2023/03/02', '2023/04/02', ]
			},
			{
				"id": "3",
				"title": "計(jì)算機(jī)行業(yè)專題研究:華為算力進(jìn)展不斷",
				"content": "圖表 3:雙十一家具銷量",
				'list': [100, 200, 220, 300, 2, 9],
				'time': ['2023/01/02', '2023/01/03', '2023/02/02', '2023/02/22', '2023/03/02', '2023/04/02', ]
			},
		]
		this.getEcharts(newList);
		// 圖表數(shù)據(jù)
		function getEcharts(newList) {
			let echartsHtml = ''
			$.each(newList, function(i, v) {
				echartsHtml += `<div class="center_img_list">
								<div class="canvas" id="canvas` + i + `" ></div>
								<div class="img_title">${v.content}</div>
								<div class="label">${v.title}</div>
							</div>`
				$(document).ready(function() {
					changeECharts(v.list, v.time, 'canvas' + i);
				})
			})
			$(".center_img_border").html(echartsHtml);
		}

		function changeECharts(changePCTRYsList, x, idname) {
			var chartDom = document.getElementById(idname);
			let objDom = {}
			objDom[idname] = echarts.init(chartDom);
			let option = {
				xAxis: [{
					type: 'category',
					boundaryGap: true,
					data: x,
					axisLabel: {
						interval: x.length - 2,
						fontSize: 12,
					},
					axisLine: {
						show: false, //隱藏x軸
					},
					axisTick: {
						show: false, //刻度線
					},
				}],
				grid: {
					left: '',
					right: 30,
					bottom: 20,
					top: 20,
					containLabel: true
				},
				tooltip: {
					show: true,
					trigger: 'axis'
				},
				yAxis: {
					show: true,
					scale: true,
					alignTicks: true,
					axisTick: {
						inside: true
					},
					type: 'value',
					min: Math.min(...changePCTRYsList),
					max: Math.max(...changePCTRYsList)
				},
				series: [{
						name: '收盤(pán)價(jià)',
						data: changePCTRYsList,
						type: 'line',
						itemStyle: {
							color: '#649E92',
						},
						symbol: 'none',
					},
					{
						name: '成交量',
						data: changePCTRYsList,
						type: 'line',
						itemStyle: {
							color: '#649E92',
						},
						symbol: 'none',
					}
				]
			};
			objDom[idname].setOption(option);
		}
	</script>

</html>

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

南漳县| 天长市| 开封县| 阜新| 崇明县| 呼图壁县| 思南县| 林西县| 许昌县| 南阳市| 南木林县| 射阳县| 新津县| 沧源| 林甸县| 秭归县| 综艺| 招远市| 衡山县| 镇康县| 日喀则市| 历史| 麻城市| 仁化县| 克拉玛依市| 新闻| 会宁县| 克什克腾旗| 武宁县| 黑河市| 怀仁县| 肃南| 元谋县| 全州县| 彭州市| 米易县| 正阳县| 张家界市| 宣汉县| 南平市| 顺义区|