From a958f8892f40c30f7b191c57ff6e5852330e04c8 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 15 Oct 2020 11:40:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=8B=E5=8A=BF=E5=9B=BE-=E6=A8=A1=E8=80=83?= =?UTF-8?q?=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_client/src/api/analyse.js | 7 ++ test_client/src/views/analyse/chart.vue | 20 ++++-- .../src/views/components/LineChart.vue | 68 ++++++------------- test_server/analyse/views.py | 12 ++-- 4 files changed, 51 insertions(+), 56 deletions(-) diff --git a/test_client/src/api/analyse.js b/test_client/src/api/analyse.js index 4248b9a..beb1104 100644 --- a/test_client/src/api/analyse.js +++ b/test_client/src/api/analyse.js @@ -35,4 +35,11 @@ export function getConsumerdis() { url: '/analyse/consumerdis/', method: 'get', }) +} + +export function getMonitest() { + return request({ + url: '/analyse/monitest/', + method: 'get', + }) } \ No newline at end of file diff --git a/test_client/src/views/analyse/chart.vue b/test_client/src/views/analyse/chart.vue index c5cdd74..e4c0084 100644 --- a/test_client/src/views/analyse/chart.vue +++ b/test_client/src/views/analyse/chart.vue @@ -14,26 +14,32 @@ - + + + + \ No newline at end of file diff --git a/test_client/src/views/components/LineChart.vue b/test_client/src/views/components/LineChart.vue index 3a6e4a7..86bee4a 100644 --- a/test_client/src/views/components/LineChart.vue +++ b/test_client/src/views/components/LineChart.vue @@ -6,7 +6,7 @@ import echarts from 'echarts' // require('echarts/theme/macarons') // echarts theme import resize from './mixins/resize' - +const animationDuration = 1000; export default { mixins: [resize], props: { @@ -40,7 +40,7 @@ export default { chartData: { deep: true, handler(val) { - this.setOptions(val) + this.initChart() } } }, @@ -59,15 +59,24 @@ export default { methods: { initChart() { this.chart = echarts.init(this.$el, 'macarons') - this.setOptions(this.chartData) - }, - setOptions({ expectedData, actualData } = {}) { - this.chart.setOption({ + if (!this.chartData.s) { + return; + } + let series = []; + for (var i = 0; i < this.chartData.s.length; i++) { + series.push({ + name: this.chartData.s[i].name, + type: "line", + data: this.chartData.s[i].data, + animationDuration, + }); + } + this.chart.setOption({ title:{ - text:'趋势分析' + text:this.chartData.t }, xAxis: { - data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], + data: this.chartData.x.data, boundaryGap: false, axisTick: { show: false @@ -77,7 +86,7 @@ export default { left: 10, right: 10, bottom: 20, - top: 30, + top: 40, containLabel: true }, tooltip: { @@ -93,46 +102,11 @@ export default { } }, legend: { - data: ['expected', 'actual'] + data: this.chartData.l }, - series: [{ - name: 'expected', itemStyle: { - normal: { - color: '#FF005A', - lineStyle: { - color: '#FF005A', - width: 2 - } - } - }, - smooth: true, - type: 'line', - data: expectedData, - animationDuration: 2800, - animationEasing: 'cubicInOut' - }, - { - name: 'actual', - smooth: true, - type: 'line', - itemStyle: { - normal: { - color: '#3888fa', - lineStyle: { - color: '#3888fa', - width: 2 - }, - areaStyle: { - color: '#f3f8ff' - } - } - }, - data: actualData, - animationDuration: 2800, - animationEasing: 'quadraticOut' - }] + series: series }) - } + }, } } diff --git a/test_server/analyse/views.py b/test_server/analyse/views.py index 72c1ff9..76c6578 100644 --- a/test_server/analyse/views.py +++ b/test_server/analyse/views.py @@ -45,14 +45,16 @@ class Monitest(APIView): 模拟考试数据-时间分布图 """ def get(self, request): - ret = {'x':{'name':'月份', 'data':[]}, 's':[{'name':'自助模考', 'data':[]}, {'name':'押卷模考', 'data':[]}], 't':'模考次数趋势图'} + ret = {'x':{'name':'月份', 'data':[]}, 's':[{'name':'模考数', 'data':[]}], 't':'趋势图', 'l':['模考数']} + # ret = {'x':{'name':'月份', 'data':[]}, 's':[{'name':'自助模考', 'data':[]}, {'name':'押卷模考', 'data':[]}], 't':'模考次数趋势图', 'l':['自助模考', '押卷模考']} tmp = ExamTest.objects.exclude(consumer__create_admin__isnull=True)\ .annotate(create_month=ExtractMonth('create_time'), create_year=ExtractYear('create_time'))\ - .values('create_month', 'create_year', 'type').order_by('create_year', 'create_month').annotate(total=Count('create_month')) + .values('create_month', 'create_year').order_by('create_year', 'create_month').annotate(total=Count('create_month')) for i in tmp: - if str(i['create_year'])+'年'+str(i['create_month'])+'月' not in ret['x']['data']: - ret['x']['data'].append(str(i['create_year'])+'年'+str(i['create_month'])+'月') - + # if str(i['create_year'])+'年'+str(i['create_month'])+'月' not in ret['x']['data']: + ret['x']['data'].append(str(i['create_year'])+'年'+str(i['create_month'])+'月') + # if i['type'] == '自助模考': + ret['s'][0]['data'].append(i['total']) return Response(ret) nameMap = {