guopengfa
发布于 2020-05-28 / 718 阅读 / 0 评论 / 0 点赞

django模板编辑返回数据

from django.shortcuts import render

def hello(request):
    return HttpResponse("Hello,world,I am GPF!")
def runoob(request):
    context = {}
    context["hello"] = "HHH,This is the request message"
    return render(request,'runoob.html',context)
def run(request):
    data = {}
    data["zlf_list"] = [20.0,40.9,30.5,50.6,70.6,40.90,120.3,23.2,120.4,10.4,40,2]
    return render(request,'echartsfinal.html',data)
'''
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>echartsTYT</title>
    <script src="https://assets.pyecharts.org/assets/echarts.min.js"></script>
</head>
<body>
<div id="view1" style="height: 700%;width: 100%"></div>
<div id="view2" style="height: 700%;width: 100%"></div>
<script>
    sdtyt = echarts.init(document.getElementById("view1"))
    options1 = {
        tooltip: {
            trigger: "axis",
            axisPointer: {
                type: "cross",
                crossType:{
                    color:"#999"
                }
            }
        },
        toolbox:{
            feature:{
                dataView: {
                    show:true,readOnly:false
                },
                magicType: {
                    show: true,
                    type: ["line","bar"]
                },
                restore: {
                    show:true
                },
                saveAsImage: {
                    show: true
                }
            }
        },
        legend:{
            data:["蒸发量","降水量","平均温度"],
            orient :"vertical",
            left: 10
        },
        xAxis:[
            {
                type:"category",
                data:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
                axisPointer: {
                    type: "shadow"
                }
            }
        ],
        yAxis: [
            {
                type: "value",
                name: "水量",
                min: 0,
                max: 250,
                interval: 5,
                axisLabel:{
                    formatter: "{value}ml"
                },
            },
            {
                type: "value",
                name: "温度",
                min: 0,
                max: 25,
                interval: 5,
                axisLabel:{
                    formatter: "{value}℃"
                }
            }
        ],
        series: [
            {
                name: "蒸发量",
                stack: "bar1",
                type: "bar",
                data: {{ zlf_list }},
            },
            {
                name: "降水量",
                stack: "bar1",
                type: "bar",
                data: [23,21,4,5,45,21,1.2,3,5,6,9,19],
            },
            {
                name: "平均温度",
                type: "line",
                data: [23.6,23,5,6,23,18,14,21,9,7,23.8,3]
            }
        ]
    };
    sdtyt.setOption(options1)
</script>
<script>
    sdtyt = echarts.init(document.getElementById("view2"))
    options1 = {
        tooltip: {
            trigger: "axis",
            axisPointer: {
                type: "cross",
                crossType:{
                    color:"#999"
                }
            }
        },
        toolbox:{
            feature:{
                dataView: {
                    show:true,readOnly:false
                },
                magicType: {
                    show: true,
                    type: ["line","bar"]
                },
                restore: {
                    show:true
                },
                saveAsImage: {
                    show: true
                }
            }
        },
        legend:{
            data:["蒸发量","降水量","平均温度"]
        },
        xAxis:[
            {
                type:"category",
                data:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
                axisPointer: {
                    type: "shadow"
                }
            }
        ],
        yAxis: [
            {
                type: "value",
                name: "水量",
                min: 0,
                max: 250,
                interval: 5,
                axisLabel:{
                    formatter: "{value}ml"
                }
            },
            {
                type: "value",
                name: "温度",
                min: 0,
                max: 25,
                interval: 5,
                axisLabel:{
                    formatter: "{value}℃"
                }
            }
        ],
        series: [
            {
                name: "蒸发量",
                type: "bar",
                data: [2.0,4.9,3.5,5.6,7.6,4.9,12.3,23.2,12.4,1.4,4,2]
            },
            {
                name: "降水量",
                type: "bar",
                data: [23,21,4,5,45,21,1.2,3,5,6,9,19]
            },
            {
                name: "平均温度",
                type: "line",
                data: [23.6,23,5,6,23,18,14,21,9,7,23.8,3]
            }
        ]
    };
    sdtyt.setOption(options1)
</script>
</body>
</html>
'''


评论