fuliqi
2024-12-12 89373b8431f8bf4b88288b1dd9de342aab8c468f
src/views/home/data-car/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>
@@ -38,10 +44,14 @@
      date: '',
      params: {
        month: '',
        category: 1
      },
      options: [
        {label: '省厅', value: 1},
        {label: '公安部', value: 2}
      ],
      categories: [
        {label: '累计数据', value: 1},
        {label: '每日数据', value: 2},
      ],
      dataList: [],
    }
@@ -78,10 +88,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'));
@@ -97,9 +110,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,
@@ -190,7 +207,7 @@
            axisLabel: {
              formatter: function (value) {
                // 返回整数部分,或使用其他逻辑来格式化标签
                return Math.floor(value);
                return Math.floor(value / interval) * interval;ge
              }
            }
          }
@@ -329,7 +346,7 @@
}
.select-container {
  margin: 0 20px;
  margin-left: 20px;
  width: 180px;
}
</style>