Commit adc3703f authored by ibuler's avatar ibuler

添加绘图

parent f31bea2c
......@@ -20,17 +20,20 @@ from jlog.models import Log
def getDaysByNum(num):
"""
输出格式:([datetime.date(2015, 11, 6), datetime.date(2015, 11, 8)], ['11-06', '11-08'])
"""
today = datetime.date.today()
oneday = datetime.timedelta(days=1)
li_date, li_str = [], []
date_li, date_str = [], []
for i in range(0, num):
today = today-oneday
li_date.append(today)
li_str.append(str(today)[5:10])
li_date.reverse()
li_str.reverse()
t = (li_date, li_str)
return t
date_li.append(today)
date_str.append(str(today)[5:10])
date_li.reverse()
date_str.reverse()
return date_li, date_str
def get_data(data, items, option):
......@@ -51,6 +54,24 @@ def get_data(data, items, option):
return dic
def get_count_by_day(date_li, item):
data_li = []
for d in date_li:
logs = Log.objects.filter(start_time__year=d.year,
start_time__month=d.month,
start_time__day=d.day)
if item == 'user':
count = len(set([log.user for log in logs]))
elif item == 'asset':
count = len(set([log.host for log in logs]))
elif item == 'login':
count = len(logs)
else:
count = 0
data_li.append(count)
return data_li
@require_role(role='user')
def index_cu(request):
user_id = request.user.id
......@@ -90,6 +111,13 @@ def index(request):
active_hosts = Asset.objects.filter(is_active=1)
week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
date_li, date_str = getDaysByNum(30)
date_month = repr(date_str)
print date_month
active_user_month = str(get_count_by_day(date_li, 'user'))
active_asset_month = str(get_count_by_day(date_li, 'asset'))
active_login_month = str(get_count_by_day(date_li, 'login'))
elif is_role_request(request, 'admin'):
return index_cu(request)
# user = get_session_user_info(request)[2]
......
......@@ -23,15 +23,7 @@
<!-- highcharts -->
<script src="/static/js/highcharts/highcharts.js"></script>
<script type="text/javascript">
require.config({
paths: {
echarts: '/static/js/echarts/chart'
}
});
</script>
<!-- echarts -->
<script src="/static/js/echarts/echarts.js"></script>
<script src="/static/js/dropzone/dropzone.js"></script>
<!-- active menu -->
......
This diff is collapsed.
......@@ -6,33 +6,34 @@
<script type="text/javascript">
require.config({
paths: {
{# 'echarts': '/static/js/echarts/chart',#}
'line': '/static/js/echarts/chart/line'
'echarts': '/static/js/echarts/chart',
'echarts/chart/line': '/static/js/echarts/chart/line'
}
});
require(
[
'line',
'echarts',
'echarts/chart/line'
],
function (ec) {
var myChart = ec.init(document.getElementById('main'));
var option = {
title : {
text: '未来一周气温变化',
text: '某楼盘销售情况',
subtext: '纯属虚构'
},
tooltip : {
trigger: 'axis'
},
legend: {
data:['最高气温','最低气温']
data:['意向','预购','成交']
},
toolbox: {
show : true,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
magicType : {show: true, type: ['line', 'bar']},
magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
restore : {show: true},
saveAsImage : {show: true}
}
......@@ -47,47 +48,35 @@
],
yAxis : [
{
type : 'value',
axisLabel : {
formatter: '{value} °C'
}
type : 'value'
}
],
series : [
{
name:'最高气温',
name:'成交',
type:'line',
data:[11, 11, 15, 13, 12, 13, 10],
markPoint : {
data : [
{type : 'max', name: '最大值'},
{type : 'min', name: '最小值'}
]
},
markLine : {
data : [
{type : 'average', name: '平均值'}
]
}
smooth:true,
itemStyle: {normal: {areaStyle: {type: 'default'}}},
data:[10, 12, 21, 54, 260, 830, 710]
},
{
name:'最低气温',
name:'预购',
type:'line',
data:[1, -2, 2, 5, 3, 2, 0],
markPoint : {
data : [
{name : '周最低', value : -2, xAxis: 1, yAxis: -1.5}
]
smooth:true,
itemStyle: {normal: {areaStyle: {type: 'default'}}},
data:[30, 182, 434, 791, 390, 30, 10]
},
markLine : {
data : [
{type : 'average', name : '平均值'}
]
}
{
name:'意向',
type:'line',
smooth:true,
itemStyle: {normal: {areaStyle: {type: 'default'}}},
data:[1320, 1132, 601, 234, 120, 90, 20]
}
]
};
myChart.setOption(option);
}
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment