使用echarts图表

1.首先在HTML中引入echarts.min.js文件:

2.然后在body中

3.在引入的index.js中先定义方法后,再在成功调用接口处调用。

datalist是来自调用接口成功时候所存储的数据。

function ts_chart() {
	var ts_chart = echarts.init(document.getElementById('tschart'));
	var data = {
		city: [],
		num: []
	}
	datalist.ts_chart.forEach((v, i) => {
		data.city.push(v.name)
		data.num.push(v.val)
	})
	option = {
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				lineStyle: {
					color: {
						type: 'linear',
						x: 0,
						y: 0,
						x2: 0,
						y2: 1,
						colorStops: [{
							offset: 0,
							color: 'rgba(255,255,255,0)' // 0% 处的颜色
						}, {
							offset: 0.5,
							color: 'rgba(255,255,255,1)' // 100% 处的颜色
						}, {
							offset: 1,
							color: 'rgba(255,255,255,0)' // 100% 处的颜色
						}],
						global: false // 缺省为 false
					}
				},
			},
	
		},
		grid: {
			top: '1%',
			left: '2%',
			right: '2%',
			bottom: '14%',
		},
		xAxis: [{
			type: 'category',
			boundaryGap: true,
			axisLine: { //坐标轴轴线相关设置。数学上的x轴
				show: true,
				lineStyle: {
					color: "rgba(7,29,43)"
				},
			},
			axisLabel: { //坐标轴刻度标签的相关设置
				textStyle: {
					color: '#cecece',
					margin: 15,
					fontSize: 8,
				},
				formatter: function(data) {
					return data
				}
			},
			axisTick: {
				show: false,
			},
			data: data.city
		}],
		yAxis: [{
			splitLine: {
				show: true,
				lineStyle: {
					color: 'rgba(7,29,43)'
				},
			},
			axisLine: {
				show: true,
				lineStyle: {
					color: "rgba(7,29,43)"
				}
	
			},
			axisLabel: {
				show: false,
				textStyle: {
					color: '#cecece',
					fontSize: 6,
	
				},
				formatter: function(value) {
					if (value === 0) {
						return value
					}
					return value + '%'
				}
			},
			axisTick: {
				show: false,
			},
		}],
		series: [{
			type: 'line',
			symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
			showAllSymbol: true,
			smooth: true,
			symbolSize: 5,
			lineStyle: {
				normal: {
					color: "#0d5c6d", // 线条颜色
				},
			},
			itemStyle: {
				color: "rgba(14,204,248,1)",
				borderColor: "#fff",
				borderWidth: 0.8
			},
			tooltip: {
				show: true
			},
			areaStyle: { //区域填充样式
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
							offset: 0,
							color: 'rgba(0,150,239,0.7)'
						},
						{
							offset: 1,
							color: 'rgba(0,253,252,0)'
						}
					], false),
					shadowColor: 'rgba(53,142,215, 0.2)', //阴影颜色
					shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
				}
			},
			data: data.num
		}]
	};
	ts_chart.setOption(option);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值