fuliqi
2024-12-25 301532b5c1cad2c1d45080bfef86579b20486bf5
src/views/home/data-face/index.vue
@@ -10,7 +10,13 @@
              </el-option>
            </el-select>
          </div>
          <div>
          <div class="select-container">
            <el-select v-model="params.category" placeholder="数据类型" @change="getChart" clearable>
              <el-option v-for="item in categories" :key="item.label" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="select-container">
            <el-date-picker v-model="date" format="yyyy-MM" value-format="yyyy-MM" type="month" placeholder="选择月份"
                            @change="dateChange">
            </el-date-picker>
@@ -28,8 +34,8 @@
import * as echarts from 'echarts';
import {car, face} from "../../../api/platform/home";
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var myChart = null;
var option;
let observer = null;
export default {
@@ -39,10 +45,14 @@
      date: '',
      params: {
        month: '',
        category: 1
      },
      categories: [
        {label: '累计数据', value: 1},
        {label: '每日数据', value: 2},
      ],
      options: [
        {label: '省厅', value: 1},
        {label: '公安部', value: 2}
        {label: '省厅', value: 1}
      ],
      dataList: [],
    }
@@ -79,10 +89,13 @@
      return tempArray;
    },
    getAllDay() {
      const currentDate = this.date.split('-');
      const currentYear = currentDate[0];
      const currentMonth = currentDate[1];
      // 获取当前日期
      const currentDate = new Date();
      const currentYear = currentDate.getFullYear();
      const currentMonth = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始,需要加1并补零
      // 获取当前月份的天数
      const daysInMonth = new Date(currentYear, currentMonth, 0).getDate();
      // 存储当前月份每一天的日期
      const datesOfMonth = [];
      for (var day = 1; day <= daysInMonth; day++) {
        const formattedDate = currentMonth + '-' + (day.toString().padStart(2, '0'));
@@ -98,9 +111,13 @@
      if (!data.list || data.list.length === 0) {
        snapCount = 0;
      }else {
        snapCount = data.list[data.list.length - 1].snapCount
        snapCount = data.list.reduce((max, item) => Math.max(max, item.snapCount), 0)
      }
      const yMax = Math.max(snapCount, baseLine * 1.2);
      const yMax = Math.max(snapCount * 1.2, baseLine * 1.2);
      let interval = 1;
      while ((yMax) / interval > 100) { // 这里的 100 是一个阈值,您可以根据需要调整
        interval *= 10;
      }
      const colors = ['#5470C6', '#66CC99', '#EE6666'];
      option = {
        color: colors,
@@ -192,7 +209,7 @@
            axisLabel: {
              formatter: function (value) {
                // 返回整数部分,或使用其他逻辑来格式化标签
                return Math.floor(value);
                return Math.floor(value / interval) * interval;
              }
            }
          }
@@ -276,6 +293,7 @@
    const month = (date.getMonth() + 1) >= 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
    this.date = year + '-' + month;
    this.params.date = this.date;
    myChart = echarts.init(this.$refs.chartContent);
    this.getChart();
    this.observe();
  },
@@ -330,7 +348,7 @@
}
.select-container {
  margin: 0 20px;
  margin-left: 20px;
  width: 180px;
}
</style>