zoukankan      html  css  js  c++  java
  • django + echarts

    my project is web

    my app is personal

    app->models.py

    class UserInfo(models.Model):
        name = models.CharField(max_length=30)
        email = models.EmailField()
        memo = models.ImageField()# .CharField(max_length=300) # upload_to='/assets'
        date_time = models.DateTimeField(auto_now=True, editable=False)
    
        class Meta:
            verbose_name_plural = '用户信息'    # modify

    app->views.py

    import pyecharts as pe
    from django.shortcuts import render
    from django.template import loader
    from pyecharts.constants import DEFAULT_HOST
    from personal.models import UserInfo
    from django.http import HttpResponse
    
    
    def create_bar():
        user_list = UserInfo.objects.all().values_list("name", "email", "memo")
        page = pe.Page()
    
        name = ["服装"]
        name2 = ["电器"]
        x = list(user_list[0])
        y = ["50", 200, 100]
        y2 = ["50", 300, 1400]
        # bar
        bar = pe.Bar("我的第一个图表", "这里是副标题", width=600, height=300)
        bar.add(name, x, y)
        bar.add(name2, x, y2)
        page.add(bar)
        # line
        line = pe.Line('Demo Line', "这里是副标题", width=600, height=300)
        line.add(name, x, y)
        line.add(name2, x, y2)
        page.add(line)
        return page
    
    
    def pyEharts(request):
        template = loader.get_template('personal/pyecharts.html')
        page = create_bar()
        context = dict(
            myechart=page.render_embed(),
            host=DEFAULT_HOST,
            script_list=page.get_js_dependencies()
        )
        return HttpResponse(template.render(context, request))

    app->urls.py

    from django.conf.urls import url
    from . import views
    
    
    urlpatterns = [
        url(r'^pe$', views.pyEharts, name='py'),
    ]

     app->templates->app->pyecharts.html

    <!-- myechartsite/djoncharts/templates/djoncharts/pyecharts.html -->
    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <title>Proudly presented by PycCharts</title>
        {% for jsfile_name in script_list %}
        <script src="{{host}}/{{jsfile_name}}.js"></script>
        {% endfor %}
    </head>
    
    <body>
      {{myechart|safe}}
    </body>
    
    </html>

    访问地址:http://127.0.0.1:8000/pe

    reference:http://pyecharts.org/#/zh-cn/django

    django and echarts: https://segmentfault.com/a/1190000011448528

    django and database: http://blog.csdn.net/zuimei_forver/article/details/50372267

  • 相关阅读:
    使用VS2013直接升级到VS2019,Cmake编译CCC4.0版本错误记录
    最近使用LuaSqlite3时,不得不说的——事务提交ATTACH语句的巨坑
    LuaSocket学习之tcp服务端
    LuaSocket HTTP 初识记录
    LuaRocks安装教程
    Lua5.1-----函数可变参数详解
    DataTable与json互转,字段类型信息丢失问题初探
    json数组与对象数组
    asp.net中封装路由信息的对象--RouteData源码
    人类的心理行为模式(几个心理学实验)
  • 原文地址:https://www.cnblogs.com/vickey-wu/p/8351212.html
Copyright © 2011-2022 走看看