Переглянути джерело

update line chart in ExamDashboard.vue

reghao 7 місяців тому
батько
коміт
9acc69e811
2 змінених файлів з 57 додано та 2 видалено
  1. 4 0
      src/api/exam.js
  2. 53 2
      src/views/exam/ExamDashboard.vue

+ 4 - 0
src/api/exam.js

@@ -139,3 +139,7 @@ export function getExamCount() {
 export function getExamPassRate() {
   return get('/api/content/exam/statistic/rate')
 }
+
+export function getLineChartData() {
+  return get('/api/content/exam/statistic/linechart')
+}

+ 53 - 2
src/views/exam/ExamDashboard.vue

@@ -69,7 +69,7 @@
 </template>
 
 <script>
-import { getExamCount, getExamPassRate, getSubjectCascade } from '@/api/exam'
+import { getExamCount, getExamPassRate, getLineChartData, getSubjectCascade } from '@/api/exam'
 
 export default {
   name: 'ExamDashboard',
@@ -126,7 +126,8 @@ export default {
           } else if (intValue === 3) {
             this.drawImg4()
           } else {
-            this.drawChart5()
+            // this.drawChart5()
+            this.drawChart6()
           }
 
           const myChart = this.$echarts.init(document.getElementById('chart1'))
@@ -313,6 +314,56 @@ export default {
         color: ['#3366CC', '#FFCC99', '#99CC33'] // 三个折线的颜色
       }
     },
+    drawChart6() {
+      getLineChartData().then(resp => {
+        if (resp.code === 0) {
+          const data = resp.data
+          this.chartOption = {
+            title: {
+              text: '卡拉云新用户激活数据',
+              subtext: 'Demo 虚构数据',
+              x: 'center'
+            },
+            tooltip: {},
+            legend: { // 图例配置选项
+              orient: 'horizontal', // 图例布局方式:水平 'horizontal' 、垂直 'vertical'
+              x: 'left', // 横向放置位置,选项:'center'、'left'、'right'、'number'(横向值 px)
+              y: 'top', // 纵向放置位置,选项:'top'、'bottom'、'center'、'number'(纵向值 px)
+              data: ['实际']
+            },
+            grid: { // 图表距离边框的距离,可用百分比和数字(px)配置
+              top: '20%',
+              left: '3%',
+              right: '10%',
+              bottom: '5%',
+              containLabel: true
+            },
+            xAxis: {
+              name: data.xName,
+              type: 'category',
+              data: data.xLabel
+            },
+            yAxis: {
+              name: data.yName,
+              type: 'value',
+              min: data.yMin, // 配置 Y 轴刻度最小值
+              max: data.yMax, // 配置 Y 轴刻度最大值
+              splitNumber: data.ySplitNumber // 配置 Y 轴数值间隔
+            },
+            series: [
+              {
+                name: '实际',
+                data: data.xValue,
+                type: 'line',
+                symbol: 'circle', // 实心圆点
+                smooth: 0.5 // 设置折线弧度
+              }
+            ],
+            color: ['#99CC33'] // 三个折线的颜色
+          }
+        }
+      })
+    },
     // 获取考试次数数据
     async getExamNumbers() {
       await getExamCount().then((resp) => {