异步ajax实例

templates下的Ajaxlineflask.html

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>Ajaxline</title>
    <style type="text/css">
    	*{
    		margin:0px;
    	}
    	#main{
    		height:400px;
    	}
    </style>
</head>
<body>
	<div id="main" style="width: 600px; height: 400px;"></div>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
	<script src="https://echarts.baidu.com/build/dist/echarts.js"></script>
	<script type="text/javascript">
		require.config({
			paths:{
				echarts:'https://echarts.baidu.com/build/dist'
			}
		});
		require(['echarts','echarts/chart/line'],
			function(ec){
				var mychart=ec.init(document.getElementById('main'));
				var option={
					title:{
					    text:'未来一周气温的变化',
						subtext:'广东省气象局'
				    		},
				    legend:{
						data:['最高气温','最低气温']
				    		},
					tooltip:{trigger:'axis'},
				    xAxis:[{
						type:'category',
						boundaryGap:false,
						data:[]
				    		}],
				    yAxis:[{
						type:'value'
				    		}],
				    series:[{
						name:'最高气温',
						type:'line',
						itemStyle:{normal:{areaStyle:{type:'default'}}},
						smooth:'true',
						data:[],
						markPoint:{
							data:[
								{type:'max',name:'最大值'},
								{type:'min',name:'最小值'}
				    				]
				    			}
				    		},
				    		{
				    			name:'最低气温',
				    			type:'line',
								itemStyle:{normal:{areaStyle:{type:'default'}}},
								smooth:'true',
				    			data:[],
				    			markPoint:{
				    				data:[
					    				{type:'max',name:'最大值'},
					    				{type:'min',name:'最小值'}
				    				]
				    			}
				    		}]
		};
		$.ajax({
            type:"GET",
            url:"http://127.0.0.1:5222/lineApi",
            success:function(data){
                console.log(data);
                option['xAxis'][0]['data']=data['xData'];
                option['series'][0]['data']=data['yDataHeight'];
                option['series'][1]['data']=data['yDataLow'];
                mychart.setOption(option);
            }
        });
        myChart.setOption(option);
	});
	</script>
</body>
</html>

app.py代码

from flask import Flask
from flask import redirect,render_template,jsonify

app=Flask(__name__)

@app.route('/')
def hello_world():
    return redirect('lineFlask')

@app.route('/lineFlask')
def line_get_flask():
    return render_template('Ajaxlineflask.html')

@app.route('/lineApi')
def list_get_api():
    return jsonify({
        "xData": ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        "yDataHeight": [11, 11, 15, 13, 2, 13, 10],
        "yDataLow": [1, -2, 2, 5, 3, 2, 0]
    })

if __name__=='__main__':
    # app.run(app.run(debug=True,port=5222,host='127.0.0.1'))
    app.run("127.0.0.1", 5222, True)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值