<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.btn{
width: 160px;
height: 50px;
}
.dis{
width: 1600px;
height: 400px;
border: 2px solid paleturquoise;
margin: 0 auto;
}
</style>
<script src="./js/jquery.min.js"></script>
<script src="./js/echarts.min.js"></script>
</head>
<body>
<input type="button" value="提交" class="btn">
<div class="dis"></div>
</body>
<script>
var btn = document.getElementsByClassName("btn")[0];
var dis = document.getElementsByClassName("dis")[0];
// 点击
btn.onclick = function () {
// 获取数据
$.get("./source/weather.json",function (data) {
// console.log(data)
var wea_data = [];
var max_temp = [];
var min_temp = [];
for(var i=0; i<data.length; i++){
wea_data.push(data[i].week_date);
max_temp.push(data[i].max_temp);
min_temp.push(data[i].min_temp);
}
// 1.初始化
var my_dis = echarts.init(dis);
// 2.配置
var option = {
title:{
text:"未来七点成都的温度变化图"
},
legend:{
left:"right"
},
xAxis:{
data:wea_data
},
yAxis: {},
series:[
{
name:"最高温度",
type:"line",
data:max_temp
},
{
name:"最低温度",
type:"line",
data:min_temp
},
]
};
// 绘图
my_dis.setOption(option)
})
}
</script>
</html>