資料分析畫圖,使用原生sql查詢資料

來源:互聯網
上載者:User

標籤:lin   config   width   列表   HERE   utc   tooltip   nec   date   

1、使用工具

https://www.hcharts.cn/

http://echarts.baidu.com/

2、子表查詢
id    建立時間              內容    處理者                     1    2017-02-01 11:11                1                     2    2017-03-01 11:11                11                     3    2017-04-01 11:11                2                     4    2017-05-01 11:11                1                     5    2017-02-02 11:11                1                        1. 思路                        處理者列表 = select 處理著 from tb                         for 處理者 in 處理者列表:                            v = select * from tb where  處理者=處理者   group by     建立時間(2017-02)                                            2. 思路                        # 每個月份全部門處理的訂單個數                        select * from tb group by 建立時間(%Y-%m)                                                                        select                             建立時間(%Y-%m),                            (select count(id) from tb as T2 where 處理者=1 and T2.ctime = T1.ctime ),                            (select count(id) from tb as T2 where 處理者=2 and T2.ctime = T1.ctime ),                        from tb as T1 group by 建立時間(%Y-%m)                        年月                  id=1      id=2                        2017-02                2                                 2017-03                0                        2017-04                0                        2017-05                1

 

def trouble_json_report(request):    reponse = []    from django.db import connection,connections    userlist = UserInfo.objects.all()    for row in userlist:        cursor = connection.cursor()        cursor.execute("""        select unix_timestamp(date_format(ctime,"%%Y-%%m-01"))*1000 ,COUNT(id) from repository_trouble WHERE processer_id=%s GROUP BY date_format(ctime,"%%Y-%%m")        """,[row.nid])        result = cursor.fetchall()        temp = {            ‘name‘:row.username,            ‘data‘:result        }        reponse.append(temp)    import json    return HttpResponse(json.dumps(reponse))

  

{% extends ‘backdemo.html‘ %}{% block title %}    article{% endblock %}{% block css %}    <style>    </style>{% endblock %}{% block modal %}{% endblock %}{% block content %}    <ol class="breadcrumb">        <li><a href="#">保障管理</a></li>        <li class="active">資料分析</li>    </ol></head><body><div id="container"></div>{% endblock %}{% block js %}<script src="/static/plugins/Highcharts/code/highcharts.js"></script>    <script>    Highcharts.setOptions({        global: {            useUTC: false        }    });    $(function(){        initChart();    });    function initChart(){        var config = {            chart: {                type: ‘spline‘            },            title: {                text: ‘動態類比即時資料‘            },            xAxis: {                type: ‘datetime‘            },            yAxis: {                title: {                    text: ‘值‘                },                plotLines: [{                    value: 0,                    width: 1,                    color: ‘#808080‘                }]            },            tooltip: {                formatter: function () {                    return ‘<b>‘ + this.series.name + ‘</b><br/>‘ +                            Highcharts.dateFormat(‘%Y-%m-%d %H:%M:%S‘, this.x) + ‘<br/>‘ +                            Highcharts.numberFormat(this.y, 2);                }            },            legend: {                enabled: true            },            exporting: {                enabled: false            },            series: [                {                    name: ‘A‘,                    data: [                        [1491535949788.035, 7.0],                        [1491535949888.035, 6.0],                        [1491535949988.035, 10.0],                        [1491535950088.035, 1.0],                    ]                },                {                    name: ‘B‘,                    data: [                        [1491535949788.035, 8.0],                        [1491535949888.035, 2.0],                        [1491535949988.035, 40.0],                        [1491535950088.035, 1.0],                    ]                }                ,                {                    name: ‘C‘,                    data: [                        [1491535949788.035, 10.0],                        [1491535949888.035, 2.0],                        [1491535949988.035, 10.0],                        [1491535950088.035, 8.0],                    ]                }            ]        };        // 資料庫中擷取 series{#        $(‘#container‘).highcharts(config);#}        $.ajax({            url: ‘/backend/trouble-json-report.html‘,            dataType: ‘json‘,            success:function(arg){                console.log(123123);                config[‘series‘] = arg;                $(‘#container‘).highcharts(config);            }        })    }</script>{% endblock %}

  

資料分析畫圖,使用原生sql查詢資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.