From 26fcbe549c5284857abacfbd79296b3732b7452d Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 18 Jan 2019 18:58:51 +0800 Subject: [PATCH] . --- chapter2/mysite/myapp/static/scripts/trend.js | 13 ++++++++++--- chapter2/mysite/myapp/templates/myapp/result.html | 1 + chapter2/mysite/myapp/views.py | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/chapter2/mysite/myapp/static/scripts/trend.js b/chapter2/mysite/myapp/static/scripts/trend.js index 57a47c2..c3f0ca5 100755 --- a/chapter2/mysite/myapp/static/scripts/trend.js +++ b/chapter2/mysite/myapp/static/scripts/trend.js @@ -83,6 +83,13 @@ $(function(){ var histogramChart2 = echarts.init(document.getElementById('histogramChart2')); + var histogramChart2_names = []; + var histogramChart2_datas = []; + for(var key in hour_sell){ + histogramChart2_names.push(key); + histogramChart2_names.push(hour_sell[key]); + } + histogramChart2.setOption({ color:['#FD6C88'], @@ -100,7 +107,7 @@ $(function(){ yAxis : [ { type : 'category', - data : ['1秒-3秒', '4-6秒', '7-9秒', '10-30秒', '30-60秒', '1-3分钟', '3-10分钟', '10-30分钟','30分钟','1-3小时','4-6小时','7-9小时','10-30小时','30-60小时','60小时'], + data : histogramChart2_names, axisLine:{ lineStyle:{ color: '#FD6C88' @@ -138,8 +145,8 @@ $(function(){ { name:'', type:'bar', - barWidth : 20, - data:[170,146,116,819,704,413,251,175,20,18,30,50,11], + barWidth : 5, + data:histogramChart2_datas, }, ] }) diff --git a/chapter2/mysite/myapp/templates/myapp/result.html b/chapter2/mysite/myapp/templates/myapp/result.html index b9e3b2d..858d098 100644 --- a/chapter2/mysite/myapp/templates/myapp/result.html +++ b/chapter2/mysite/myapp/templates/myapp/result.html @@ -10,6 +10,7 @@ var from_type_info = {{from_type_info|safe}}; var top10_sells = {{top10_sells|safe}}; var last_month_sell = {{last_month_sell|safe}}; + var hour_sell = {{hour_sell|safe}}; diff --git a/chapter2/mysite/myapp/views.py b/chapter2/mysite/myapp/views.py index 367104f..53ea574 100644 --- a/chapter2/mysite/myapp/views.py +++ b/chapter2/mysite/myapp/views.py @@ -32,5 +32,7 @@ def result(request): top10_sells = [entry for entry in Top10Sells.objects.order_by('id').values()] last_month_sell = json.loads(Datas.objects.filter(key='last_month_sell').first().data) + + hour_sell = json.loads(Datas.objects.filter(key='hour_sell').first().data) return render(request, 'myapp/result.html', {"from_type_info": from_type_info, - "top10_sells": top10_sells, "last_month_sell": last_month_sell}) \ No newline at end of file + "top10_sells": top10_sells, "last_month_sell": last_month_sell, "hour_sell": hour_sell}) \ No newline at end of file