Echarts+jsonp+flask 数据可视化

  • py文件
    from flask import Flask, render_template, Response, request ,jsonify
    import json
    
    app = Flask(__name__)
    
    xtype = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    xdata = [5, 20, 36, 10, 10, 20]
    json_data = json.dumps({"xtype": xtype, "xdata": xdata})
    
    
    @app.route('/echarts')
    def tem():
        return render_template('bar.html')
    
    
    @app.route('/data')
    def data():
        callback = request.args.get('callback')
        # 支持jsonp方式的api接口
        return Response('{}({})'.format(callback, json_data))
        # 【如果是这个格式的,那么 ↓ 就可以不使用jsonp方式。】
        # return jsonify({"xtype": xtype, "xdata": xdata})
        
    
    app.run()
    
  • bar.html
    
    
    
        
        bar
        
        
    
    
    
  • 访问:http://127.0.0.1:5000/echarts

你可能感兴趣的:(Echarts+jsonp+flask 数据可视化)