VUE3:统计分析页面布局+自适应页面参考

news2024/9/22 9:53:09

一、布局

<template>
    <div class="container1">
        <div class="form white">
            <el-form :inline="true" :rules="rules" :model="queryParams" label-width="80px" ref="querParmRef">
                <el-form-item label="城市" prop="cityId">

                    <el-select v-model="queryParams.cityId" clearable filterable placeholder="请选择城市" style="width: 169px">
                        <el-option v-for="item in citylists" :key="item.english" :label="item.english"
                            :value="item.chinese">
                        </el-option> </el-select>

                </el-form-item>
                <el-form-item label="公司" prop="companyId">

                    <el-select v-model="queryParams.companyId" clearable filterable placeholder="请选择公司"
                        style="width: 169px">
                        <el-option v-for="item in citylists" :key="item.english" :label="item.english"
                            :value="item.chinese">
                        </el-option> </el-select>

                </el-form-item>
                <el-form-item label="日期" prop="date">
                    <el-date-picker v-model="queryParams.date" value-format="YYYY-MM-DD" style="width: 169px" type="date"
                        placeholder="" />

                </el-form-item>

                <el-form-item label="对比日期" prop="date">
                    <el-date-picker v-model="queryParams.date" value-format="YYYY-MM-DD" style="width: 169px" type="date"
                        placeholder="" />

                </el-form-item>
                <el-form-item>
                    <el-button @click="resetQuery">重置</el-button>
                    <el-button type="primary" @click="btntop()" class="btnClick">搜索</el-button>
                </el-form-item>

                <!-- <el-form-item label="起止时间">
                    <el-date-picker style="width: 358px" v-model="queryParams.timeValue" type="datetimerange"
                        range-separator="-" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始时间"
                        end-placeholder="结束时间" :size="size" />
                </el-form-item> -->
                <div>
                </div>
            </el-form>
        </div>

        <div class="echartsBot white">
            <el-tabs v-model="activeName" class="tabs">
                <el-tab-pane label="1" name="first"></el-tab-pane>
                <el-tab-pane label="2" name="second">2</el-tab-pane>
                <el-tab-pane label="3" name="third">3</el-tab-pane>
            </el-tabs>
            <!-- 上部分 -->
            <div class="top">
                <!-- 左边 -->
                <div class="left">
                    <div class="chart chart1"></div>
                    <div class="chart chart2"></div>
                </div>
                <!-- 中间 -->
                <div class="middle">
                    <div class="chart chart3"></div>
                </div>
                <!-- 右边 -->
                <div class="right">
                    <div class="chart chart4"></div>
                </div>
            </div>
            <!-- 下部分 -->
            <div class="bottom">
                <div class="chart chart5"></div>
                <div class="chart chart6"></div>
                <div class="chart chart7"></div>
                <div class="chart chart8"></div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.container1 {
    padding: calc(100vw * 15 / 1920);
    display: flex;
    flex-direction: column;
    /* 设置垂直方向排列 */
    height: 100%;
    width: 100%;
    background-color: #F7F8FA;

}

.white {
    background-color: #fff;
}

.echartsBot {
    flex: 1;
    width: 100%;
    padding: 0 calc(100vw * 15 / 1920) calc(100vw * 15 / 1920);
    margin-top: calc(100vw * 10 / 1920);
}

.titles1 {
    width: 100%;
    height: calc(100vw * 20 / 1920);
    font-size: calc(100vw * 14 / 1920);
    font-weight: 600;
    color: #1d2129;
    line-height: calc(100vw * 20 / 1920);
    padding-left: 1vh;
}


/* 上部分 */
.echartsBot .top {
    display: flex;
    height: calc(65% - 50px)
}

/* 左边 */
.echartsBot .left {
    width: 46%;
    display: flex;
    flex-direction: column;
    margin-right: calc(100vw * 15 / 1920);

}

/* 中间 */
.echartsBot .middle {
    width: 27%;
    background-color: #5be948;
    margin-right: calc(100vw * 15 / 1920);

}

/* 右边 */
.echartsBot .right {
    width: 27%;
    background-color: #1e7f97;

}

/* 柱状图 */
.echartsBot .chart {
    /* 修改为需要的宽度和高度 */
    // width: 300px;
    // height: 200px;
}

/* 左边的柱状图 */
.echartsBot .left .chart1 {
    /* 样式设置 */
    flex:1;
    margin-bottom: calc(100vw * 15 / 1920);
    background-color: #64b959;

}

.echartsBot .left .chart2 {
    /* 样式设置 */
    flex:1;
    background-color: #8d2424;

}

/* 中间的柱状图 */
.echartsBot .middle .chart3 {
    /* 样式设置 */
}

/* 右边的柱状图 */
.echartsBot .right .chart4 {
    /* 样式设置 */
}

/* 下部分 */
.echartsBot .bottom {
    display: flex;
    // height: 40%;
    margin-top: calc(100vw * 15 / 1920); // height: calc(50%- 10px);
    height: calc(35% - calc(100vw * 19 / 1920));
}

/* 底部柱状图 */
.echartsBot .bottom .chart {
    /* 修改为需要的宽度和高度 */
    // width: 200px;
    // height: 150px;
}

.echartsBot .bottom .chart5 {
    /* 样式设置 */
    flex: 1;
    background-color: #ecd2d2;
    height: 100%;
    margin-right: calc(100vw * 15 / 1920);


}

.echartsBot .bottom .chart6 {
    /* 样式设置 */
    flex: 1;
    margin-right: calc(100vw * 15 / 1920);

    background-color: #b6c789;
    height: 100%;

}

.echartsBot .bottom .chart7 {
    /* 样式设置 */
    flex: 1;
    margin-right: calc(100vw * 15 / 1920);

    background-color: #a7a2e0;
    height: 100%;

}

.echartsBot .bottom .chart8 {
    /* 样式设置 */
    flex: 1;

    background-color: #dba6d0;
    height: 100%;

}
</style>

 上面效果图的代码,用的flex布局,宽高边距都用了动态的,浏览器窗口大小改变也会自适应

二、分完模块优化

最终效果图如上

完整版代码

 

<template>
    <div class="container1">
        <div class="form white">
            <el-form :inline="true" :rules="rules" :model="queryParams" label-width="80px" ref="querParmRef">
                <el-form-item label="城市" prop="cityId">

                    <el-select v-model="queryParams.cityId" clearable filterable placeholder="请选择城市" style="width: 169px">
                        <el-option v-for="item in citylists" :key="item.english" :label="item.english"
                            :value="item.chinese">
                        </el-option> </el-select>

                </el-form-item>
             
                <el-form-item label="公司" prop="companyId">

                    <el-select v-model="queryParams.companyId" clearable filterable placeholder="请选择公司"
                        style="width: 169px">
                        <el-option v-for="item in citylists" :key="item.english" :label="item.english"
                            :value="item.chinese">
                        </el-option> </el-select>

                </el-form-item>
                <el-form-item label="日期" prop="date">
                    <el-date-picker v-model="queryParams.date" value-format="YYYY-MM-DD" style="width: 169px" type="date"
                        placeholder="" />

                </el-form-item>

                <el-form-item label="对比日期" prop="date">
                    <el-date-picker v-model="queryParams.date" value-format="YYYY-MM-DD" style="width: 169px" type="date"
                        placeholder="" />

                </el-form-item>
                <el-form-item>
                    <el-button @click="resetQuery">重置</el-button>
                    <el-button type="primary" @click="btntop()" class="btnClick">搜索</el-button>
                </el-form-item>

                <!-- <el-form-item label="起止时间">
                    <el-date-picker style="width: 358px" v-model="queryParams.timeValue" type="datetimerange"
                        range-separator="-" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始时间"
                        end-placeholder="结束时间" :size="size" />
                </el-form-item> -->
                <div>
                </div>
            </el-form>
        </div>

        <div class="echartsBot white">
            <el-tabs v-model="activeName" class="tabs">
                <el-tab-pane label="1" name="first"></el-tab-pane>
                <!-- <el-tab-pane label="冷热能效耗能排名总览" name="first"></el-tab-pane> -->
                <el-tab-pane label="2" name="second">2</el-tab-pane>
                <el-tab-pane label="3" name="third">3</el-tab-pane>
            </el-tabs>
            <!-- 上部分 -->
            <div class="top">
                <!-- 左边 -->
                <div class="left">
                    <div class="chart chart1">
                        <div class="titles1">面积排名</div>
                        <Echarts1 :echartList="echartList1" />

                    </div>
                    <div class="chart chart2">
                        <div class="titles1">运营天数排名</div>

                        <Echarts2 :echartList="echartList2" />

                    </div>
                </div>
                <!-- 中间 -->
                <div class="middle">
                    <div class="titles1">COP排名</div>
                    <Echarts3 :echartList="echartList3" />

                    <!-- <div class="chart chart3"></div> -->

                </div>
                <!-- 右边 -->
                <div class="right">
                    <div class="titles1">SCOP排名</div>
                    <Echarts4 :echartList="echartList4" />
                </div>
            </div>
            <!-- 下部分 -->
            <div class="bottom">
                <div class="chart chart5">
                    <div class="titles1">热单耗排名</div>

                    <Echarts5 :echartList="echartList5" />

                </div>
                <div class="chart chart6">
                    <div class="titles1">热单耗排名</div>

                    <Echarts6 :echartList="echartList6" />
                </div>
                <div class="chart chart7">
                    <div class="titles1">热单耗排名</div>

                    <Echarts7 :echartList="echartList7" />
                </div>
                <div class="chart chart8">
                    <div class="titles1">热单耗排名</div>

                    <Echarts8 :echartList="echartList8" />
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
import { ElMessageBox, ElMessage, ElLoading } from "element-plus";
import Echarts1 from "./echarts/echarts1.vue";
import Echarts2 from "./echarts/echarts2.vue";
import Echarts3 from "./echarts/echarts3.vue";
import Echarts4 from "./echarts/echarts4.vue";
import Echarts5 from "./echarts/echarts5.vue";
import Echarts6 from "./echarts/echarts6.vue";
import Echarts7 from "./echarts/echarts7.vue";
import Echarts8 from "./echarts/echarts8.vue";
const { proxy } = getCurrentInstance();
import { parseTime } from "@/utils/ruoyi";
import { useRoute } from "vue-router";

const echartList1 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
]);
const echartList2 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },


]);
const echartList3 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },


]);
const echartList4 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }


])
const echartList5 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 },
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }


])
const echartList6 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }


])
const echartList7 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }


])
const echartList8 = ref([
    { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }, { cityName: '济南', parkArea: 12 }


])
const activeName = ref('first')
</script>
<style scoped lang="scss">
.container1 {
    padding: calc(100vw * 15 / 1920);
    display: flex;
    flex-direction: column;
    /* 设置垂直方向排列 */
    height: 100%;
    width: 100%;
    background-color: #F7F8FA;

}

.white {
    background-color: #fff;
}

.echartsBot {
    flex: 1;
    width: 100%;
    padding: 0 calc(100vw * 15 / 1920) ;
    margin-top: calc(100vw * 10 / 1920);
}

.titles1 {
    width: 100%;
    height: calc(100vw * 20 / 1920);
    font-size: calc(100vw * 14 / 1920);
    font-weight: 600;
    color: #1d2129;
    line-height: calc(100vw * 20 / 1920);
    padding-left: 1vh;
}


/* 上部分 */
.echartsBot .top {
    display: flex;
    height: calc(63% - 50px)
}

/* 左边 */
.echartsBot .left {
    width: 46%;
    display: flex;
    flex-direction: column;
    margin-right: calc(100vw * 15 / 1920);

}

/* 中间 */
.echartsBot .middle {
    width: 27%;
    // padding: calc(100vw * 15 / 1920);

    margin-right: calc(100vw * 15 / 1920);
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}

/* 右边 */
.echartsBot .right {
    width: 27%;
    // padding: calc(100vw * 15 / 1920);

    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}

/* 柱状图 */
.chart {
    /* 修改为需要的宽度和高度 */
    // width: 300px;
    // height: 200px;
    // padding: calc(100vw * 15 / 1920);

}

/* 左边的柱状图 */
.echartsBot .left .chart1 {
    /* 样式设置 */
    height: calc(50% - calc(100vw * 16 / 1920));
    margin-bottom: calc(100vw * 10 / 1920);
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}

.echartsBot .left .chart2 {
    /* 样式设置 */
    flex: 1;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}

/* 中间的柱状图 */
.echartsBot .middle .chart3 {
    /* 样式设置 */
}

/* 右边的柱状图 */
.echartsBot .right .chart4 {
    /* 样式设置 */
}

/* 下部分 */
.echartsBot .bottom {
    display: flex;
    // height: 40%;
    margin-top: calc(100vw * 15 / 1920); // height: calc(50%- 10px);
    height: calc(35% - calc(100vw * 19 / 1920));
}

/* 底部柱状图 */
.echartsBot .bottom .chart {
    /* 修改为需要的宽度和高度 */
    // width: 200px;
    // height: 150px;
}

.echartsBot .bottom .chart5 {
    /* 样式设置 */
    flex: 1;
    height: 100%;
    margin-right: calc(100vw * 15 / 1920);
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);

}

.echartsBot .bottom .chart6 {
    /* 样式设置 */
    flex: 1;
    margin-right: calc(100vw * 15 / 1920);

    height: 100%;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}

.echartsBot .bottom .chart7 {
    /* 样式设置 */
    flex: 1;
    margin-right: calc(100vw * 15 / 1920);

    height: 100%;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}

.echartsBot .bottom .chart8 {
    /* 样式设置 */
    flex: 1;

    height: 100%;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid rgba(61, 61, 61, 0.1);
}
</style>

具体echarts图

第一个

<template>
  <div id="echarts1"></div>
</template>

<script setup>
import * as echarts from "echarts";
const emit = defineEmits();

const props = defineProps({
  echartList: {
    default: [],
  },
});
const initChart = () => {
  let xdata = [];
  let ydata1 = [];
  let xdataid = [];
  props.echartList.forEach((item) => {
    xdata.push(item.cityName);
    xdataid.push(item.cityId);
    ydata1.push(item.parkArea);
  });
  const machart = echarts.init(document.getElementById("echarts1"));
  var defaultShowNum = 10; // 默认显示的数据条数

  var start = 0;
  var end = Math.min(defaultShowNum, xdata.length) / xdata.length * 100;
  var option = {
    tooltip: {
      trigger: "axis",
      formatter: '{c}', // 修改为只显示名称和数值

      backgroundColor: 'rgba(255,255,255,0.8)', // 气泡框背景颜色
      textStyle: {
        color: '#333', // 文字颜色
        fontSize: 14 // 文字大小
      },
      position: function (pos, params, el, elRect, size) {
        return { left: pos[0], top: pos[1] };
      }, // 设置气泡框的位置在鼠标悬浮的地方
      padding: [10, 10, 10, 10], // 设置气泡框的内边距
      extraCssText: 'width: auto; height: auto; text-align: center; line-height: 30px;', // 设置气泡框的宽度、高度、文本居中显示

    },
    dataZoom: [
      {
        type: 'slider', // 缩放条类型为滑动条
        show: true, // 显示缩放条
        start: start, // 根据数据计算的开始位置
        end: end, // 根据数据计算的结束位置
        bottom: '5%', // 距离底部的距离
        height: 5, // 设置高度
      },
      {
        type: 'inside', // 内置缩放条
        start: start,
        end: end,
      },
    ],
    calculable: true,
    // legend: {
    //   // data: ["xxx"],
    //   left: "left",s
    //   x: "left",
    //   top: "0%",
    //   left: "2%",
    //   icon: "roundRect",
    //   itemWidth: 10, // 设置宽度
    //   itemHeight: 10, // 设置高度
    // },
    color: ["#579AFF", "#B1B1F0", "#F7BEBE", '#BDF6E6'],
    grid: {
      top: "14sss%",
      bottom: "10%",
      left: "1%",
      right: "1%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: xdata,
        axisTick: {
          show: false, // 不显示刻度
        },

      },
    ],
    yAxis: [
      {
        type: "value",

      },
    ],

    series: [
      {
        // name: "城市占比",
        type: "bar",
        data: ydata1,
        barWidth: "35%",
        //   label: { // 添加标签配置
        //   show: true, // 显示标签
        //   position: 'top', // 标签位置为柱子顶部
        //   formatter: '{c} ', // 标签内容格式为数据加单位
        // },
      },

    ],
  };
  machart.setOption(option);
  setTimeout(() => {
    window.addEventListener("resize", resizeFn);
  }, 100);
  const resizeFn = () => {
    return machart.resize();
  };
  machart.on("click", (params) => {
    if (params.componentType === "series") {
      const dataIndex = params.dataIndex;
      const yValue = xdata[dataIndex]; // 获取对应柱子的y值
      const cidtyid = xdataid[dataIndex]; // 获取对应柱子的y值
      emit("changedi", yValue, cidtyid);

      // 在这里你可以对获取到的y值进行其他操作,比如弹窗显示等
    }
  });
};
setTimeout(() => {
  initChart();
}, 800);
defineExpose({
  initChart,
});
onBeforeUnmount(() => {
  // 离开页面必须进行移除,否则会造成内存泄漏,导致卡顿
  window.removeEventListener("resize", initChart);
});
</script>

<style scoped>
#echarts1 {
  width: 100%;
  height: 95%;
  /* height:    calc(30vh- 10px); */
}
</style>

右边两个

<template>
  <div id="echarts3"></div>
</template>

<script setup>
import * as echarts from "echarts";
const emit = defineEmits();

const props = defineProps({
  echartList: {
    default: [],
  },
});
const initChart = () => {
  let xdata = [];
  let ydata1 = [];
  let xdataid = [];
  props.echartList.forEach((item) => {
    xdata.push(item.cityName);
    xdataid.push(item.cityId);
    ydata1.push(item.parkArea);
  });
  const machart = echarts.init(document.getElementById("echarts3"));
  var defaultShowNum = 10; // 默认显示的数据条数

  var start = 0;
  var end = Math.min(defaultShowNum, xdata.length) / xdata.length * 100;
  var option = {
    tooltip: {
      trigger: "axis",
      formatter: '{c}', // 修改为只显示名称和数值

      backgroundColor: 'rgba(255,255,255,0.8)', // 气泡框背景颜色
      textStyle: {
        color: '#333', // 文字颜色
        fontSize: 14 // 文字大小
      },
      position: function (pos, params, el, elRect, size) {
        return { left: pos[0], top: pos[1] };
      }, // 设置气泡框的位置在鼠标悬浮的地方
      padding: [10, 10, 10, 10], // 设置气泡框的内边距
      extraCssText: 'width: auto; height: auto; text-align: center; line-height: 30px;', // 设置气泡框的宽度、高度、文本居中显示

    },
    dataZoom: [
      {
        type: 'slider',
        orient: 'vertical', // 设置为垂直方向
        show: true,
        start: start,
        end: end,
        right: 0, // 距离右侧的距离
        width: 10, // 设置宽度
      },
      {
        type: 'inside', // 内置缩放条
        start: start,
        end: end,
      },
    ],
    calculable: true,
    // legend: {
    //   // data: ["xxx"],
    //   left: "left",s
    //   x: "left",
    //   top: "0%",
    //   left: "2%",
    //   icon: "roundRect",
    //   itemWidth: 10, // 设置宽度
    //   itemHeight: 10, // 设置高度
    // },
    // color: ["#579AFF", "#B1B1F0", "#F7BEBE", '#BDF6E6'],
    grid: {
      top: "5%",
      bottom: "1%",
      left: "1%",
      right: "8%",
      containLabel: true,
    },
    yAxis: [
      {
        type: "category",
        data: xdata.reverse(),
        axisLine: {
          show: false, // 隐藏坐标轴线
        },
        axisTick: {
          show: false, // 不显示刻度线
        },
        axisLabel: {
          show: true, // 显示坐标轴标签
        },
      },
    ],
    xAxis: [
      {
        type: "value",
        show: false, // 不显示x轴
      },
    ],

    series: [
      {
        // name: "城市占比",
        type: "bar",
        data: ydata1.reverse(),
        barWidth: "35%",
        itemStyle: {
          color: function (params) {
            if (params.dataIndex >= xdata.length - 3) {
              // 最后三条数据
              if (params.dataIndex === xdata.length - 1) {
                return '#E96163'; // 设置最后一条数据的颜色
              } else if (params.dataIndex === xdata.length - 2) {
                return '#FEA935'; // 设置倒数第二条数据的颜色
              } else {
                return '#F0DC5A'; // 设置倒数第三条数据的颜色
              }
            } else {
              return '#579AFF'; // 其他数据的颜色
            }
          }
        },

      },

    ],
  };
  machart.setOption(option);
  setTimeout(() => {
    window.addEventListener("resize", resizeFn);
  }, 100);
  const resizeFn = () => {
    return machart.resize();
  };
  machart.on("click", (params) => {
    if (params.componentType === "series") {
      const dataIndex = params.dataIndex;
      const yValue = xdata[dataIndex]; // 获取对应柱子的y值
      const cidtyid = xdataid[dataIndex]; // 获取对应柱子的y值
      emit("changedi", yValue, cidtyid);

      // 在这里你可以对获取到的y值进行其他操作,比如弹窗显示等
    }
  });
};
setTimeout(() => {
  initChart();
}, 800);
defineExpose({
  initChart,
});
onBeforeUnmount(() => {
  // 离开页面必须进行移除,否则会造成内存泄漏,导致卡顿
  window.removeEventListener("resize", initChart);
});
</script>

<style scoped>
#echarts3 {
  width: 100%;
  height: 95%;
  /* height:    calc(30vh- 10px); */
}
</style>

最下面的

<template>
  <div id="echarts8"></div>
</template>

<script setup>
import * as echarts from "echarts";
const emit = defineEmits();

const props = defineProps({
  echartList: {
    default: [],
  },
});
const initChart = () => {
  let xdata = [];
  let ydata1 = [];
  let xdataid = [];
  props.echartList.forEach((item) => {
    xdata.push(item.cityName);
    xdataid.push(item.cityId);
    ydata1.push(item.parkArea);
  });
  const machart = echarts.init(document.getElementById("echarts8"));
  var defaultShowNum = 10; // 默认显示的数据条数

  var start = 0;
  var end = Math.min(defaultShowNum, xdata.length) / xdata.length * 100;
  var option = {
    tooltip: {
      trigger: "axis",
      formatter: '{c}', // 修改为只显示名称和数值

      backgroundColor: 'rgba(255,255,255,0.8)', // 气泡框背景颜色
      textStyle: {
        color: '#333', // 文字颜色
        fontSize: 14 // 文字大小
      },
      position: function (pos, params, el, elRect, size) {
        return { left: pos[0], top: pos[1] };
      }, // 设置气泡框的位置在鼠标悬浮的地方
      padding: [10, 10, 10, 10], // 设置气泡框的内边距
      extraCssText: 'width: auto; height: auto; text-align: center; line-height: 30px;', // 设置气泡框的宽度、高度、文本居中显示

    },
    dataZoom: [
      {
        type: 'slider', // 缩放条类型为滑动条
        show: true, // 显示缩放条
        start: start, // 根据数据计算的开始位置
        end: end, // 根据数据计算的结束位置
        bottom: 10, // 距离底部的距离
        height: 5, // 设置高度
      },
      {
        type: 'inside', // 内置缩放条
        start: start,
        end: end,
      },
    ],
    calculable: true,
    // legend: {
    //   // data: ["xxx"],
    //   left: "left",s
    //   x: "left",
    //   top: "0%",
    //   left: "2%",
    //   icon: "roundRect",
    //   itemWidth: 10, // 设置宽度
    //   itemHeight: 10, // 设置高度
    // },
    color: ["#579AFF", "#B1B1F0", "#F7BEBE", '#BDF6E6'],
    grid: {
      top: "8%",
      bottom: "8%",
      left: "1%",
      right: "1%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: xdata,
        axisTick: {
          show: false, // 不显示刻度
        },

      },
    ],
    yAxis: [
      {
        type: "value",

      },
    ],

    series: [
      {
        // name: "城市占比",
        type: "bar",
        data: ydata1,
        barWidth: "35%",
        itemStyle: {
          color: function (params) {
            // 判断是否为最上面的三个柱子,分别设置为红色、橘色、黄色
            if (params.dataIndex <= 2) {
              return params.dataIndex === 0 ? '#E96163' : params.dataIndex === 1 ? '#FEA935' : '#F0DC5A';
            } else {
              return '#D9D9D9'; // 设置其他柱子的颜色
            }
          }
        },
      },

    ],
  };
  machart.setOption(option);
  setTimeout(() => {
    window.addEventListener("resize", resizeFn);
  }, 100);
  const resizeFn = () => {
    return machart.resize();
  };
  machart.on("click", (params) => {
    if (params.componentType === "series") {
      const dataIndex = params.dataIndex;
      const yValue = xdata[dataIndex]; // 获取对应柱子的y值
      const cidtyid = xdataid[dataIndex]; // 获取对应柱子的y值
      emit("changedi", yValue, cidtyid);

      // 在这里你可以对获取到的y值进行其他操作,比如弹窗显示等
    }
  });
};
setTimeout(() => {
  initChart();
}, 800);
defineExpose({
  initChart,
});
onBeforeUnmount(() => {
  // 离开页面必须进行移除,否则会造成内存泄漏,导致卡顿
  window.removeEventListener("resize", initChart);
});
</script>

<style scoped>
#echarts8 {
  width: 100%;
  height: 95%;
  /* height:    calc(30vh- 10px); */
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1481055.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于NeRF/Gaussian的全新SLAM算法

什么是SLAM&#xff1f; SLAM&#xff0c;即同时定位与地图构建技术&#xff0c;SLAM可以让机器人、无人机和其他自动化系统能够在未知环境中同时进行自我定位和环境映射。 为什么是NeRF-Based SLAM&#xff1f; 传统CG将输入图像重新投影再融合到新的视图摄像机中&#xff0c…

useState多次渲染页面卡顿 useMemo

useState多次渲染页面卡顿 state变化了组件自然应该重新进行渲染&#xff0c;但有时我们并不需要。 React.memo()(useMemo)是一个高阶组件&#xff0c;它接收另一个组件作为参数&#xff0c;并且会返回一个包装过的新组件&#xff0c;包装过的新组件就会具有缓存作用&#xff…

Qt 中Qwidget相关属性

文章目录 1. QWidget 核心属性1.1 enabled1.2 geometry1.2.1 window frame 的影响 1.3 windowTitle1.4 windowIcon1.4.1 qrc的使用 1.5 windowOpacity1.6 cursor1.7 focusPolicy1.8 styleSheet 1. QWidget 核心属性 在 Qt 中, 使⽤ QWidget 类表⽰ “控件”. 像按钮, 视图, 输…

MES系统在离散制造企业中的功能解析

随着信息技术的快速发展和制造业的转型升级&#xff0c;MES在离散制造企业中的作用日益凸显。MES系统不仅提高了生产效率和产品质量&#xff0c;还优化了资源配置&#xff0c;增强了企业的市场竞争力。 一、生产管理功能 MES系统能够实时监控生产现场的各种数据&#xff0c;包…

数据库常见理论常见面试题(总结)

一、前言 这里呢&#xff0c;博主会介绍一些平时关于数据库的理论的问题&#xff0c;比如数据库的三级模式两级映射、触发器、范式、存储过程、视图等等概念知识&#xff0c;但是像索引、事务、锁等内容&#xff0c;之前的文章就讲解过了&#xff0c;这里就不作过多的介绍了&am…

基于Beego 1.12.3的简单website实现

参考 用Beego开发web应用 https://www.cnblogs.com/zhangweizhong/p/10919672.htmlBeego官网 Homepage - beego: simple & powerful Go app frameworkbuild-web-application-with-golang https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/pr…

猫头虎的技术林: 加速你的Python项目 - 如何配置国内pip下载源

博主猫头虎的技术世界 &#x1f31f; 欢迎来到猫头虎的博客 — 探索技术的无限可能&#xff01; 专栏链接&#xff1a; &#x1f517; 精选专栏&#xff1a; 《面试题大全》 — 面试准备的宝典&#xff01;《IDEA开发秘籍》 — 提升你的IDEA技能&#xff01;《100天精通鸿蒙》 …

vue3基础教程(1)——nodejs环境搭建

博主个人小程序已经上线&#xff1a;【中二少年工具箱】 小程序二维如下&#xff1a; 正文开始 专栏简介1. 环境菜单2.为什么下载node3. nodejs简介4. nodejs安装5. 编辑器选择 专栏简介 本系列文章由浅入深&#xff0c;从基础知识到实战开发&#xff0c;非常适合入门同学。…

【论文阅读】《PRODIGY: Enabling In-context Learning Over Graphs》

文章目录 0、基本介绍1、研究动机2、创新点3、挑战4、准备4.1、图上分类任务4.2、少样本提示4.3、提示图表示4.3.1、Data graph G D \mathcal{G}^D GD4.3.2、task graph G T \mathcal{G}^T GT 5、方法论5.1、提示图上的信息传播架构5.1.1、Data graph Message Passing5.1.2、…

开源版视频Diffusion Transformer来了吗?

今天分享的这篇文章来自于上海人工智能实验室&#xff0c;论文的Title为&#xff1a;Latte: Latent Diffusion Transformer for Video Generation。该方法探索如何有效的对视频中的时间、空间信息进行建模&#xff0c;将视频信息有效的处理成连续的tokens。另外在如何提高视频生…

leedcode刷题--day7(字符串)

23 文章讲解 力扣地址 C class Solution { public:void reverseString(vector<char>& s) {int left 0;int right s.size() - 1; // right 应该初始化为 s.size() - 1while (left < right) {swap(s[left], s[right]); // 直接交换 s[left] 和 s[right] 的值lef…

【rust】11、所有权

文章目录 一、背景二、Stack 和 Heap2.1 Stack2.2 Heap2.3 性能区别2.4 所有权和堆栈 三、所有权原则3.1 变量作用域3.2 String 类型示例 四、变量绑定背后的数据交互4.1 所有权转移4.1.1 基本类型: 拷贝, 不转移所有权4.1.2 分配在 Heap 的类型: 转移所有权 4.2 Clone(深拷贝)…

【论文阅读-基于VilLBERT方法的导航】Vison-Language Navigation 视觉语言导航(2)

文章目录 1. 【2023ICCV】Learning Vision-and-Language Navigation from YouTube Videos摘要和结论引言Building VLN Dataset from YouTube Videos模型框架实验 2. 【2021ICCV】Airbert: In-domain Pretraining for Vision-and-Language Navigation摘要和结论引言BnB DatasetA…

JavaWeb之 Web概述

目录 前言1.1 Web和 JavaWeb的概念1.2 JavaWeb技术栈1.2.1 B/S架构1.2.2 静态资源1.2.3 动态资源1.2.4 数据库1.2.5 HTTP协议1.2.6 Web服务器 1.3 JavaWeb 学习内容 前言 博主将用 CSDN 记录 Java 后端开发学习之路上的经验&#xff0c;并将自己整理的编程经验和知识分享出来&a…

3.1作业

作业要求&#xff1a; 通过w(红色臂角度增大)s&#xff08;红色臂角度减小&#xff09;d&#xff08;蓝色臂角度增大&#xff09;a&#xff08;蓝色臂角度减小&#xff09;按键控制机械臂 程序代码&#xff1a; #include<myhead.h> #define SER_IP "192.168.126.…

《C++ Primer Plus》《10、对象和类》

文章目录 前言&#xff1a;1 过程性编程和面向对象编程2 抽象和类2.1 类型是什么2.2 C中的类2.3 实现类成员函数2.4 使用类 3 类的构造函数和析构函数3.1 声明和定义构造函数3.2 使用构造函数3.3 默认构造函数3.4 析构函数 4 this指针5 对象数组6 类的作用域6.1 作用域为类的常…

云计算 2月20号 (认识操作系统)

1、认识操作系统 计算机系统的组成 知识点1&#xff1a;没有软件系统的计算机称之为"裸机" 知识点2&#xff1a;裸机提供基本的可计算性资源 知识点3&#xff1a;操作系统是最靠近硬件的软件层&#xff0c;负责管理和控制计算机硬件。 计算机硬件组成五大部件 运算器…

1美元持有ZKFair PFP-CyberArmy,潜在收益分析

3月2日&#xff0c;ZKFair PFP-CyberArmy 将在 Element 上正式开始Public Sale。

C++基于多设计模式下的同步异步日志系统day2

&#x1f4df;作者主页&#xff1a;慢热的陕西人 &#x1f334;专栏链接&#xff1a;C基于多设计模式下的同步&异步日志系统 &#x1f4e3;欢迎各位大佬&#x1f44d;点赞&#x1f525;关注&#x1f693;收藏&#xff0c;&#x1f349;留言 主要内容实现了日志代码设计的实…

防御保护课程笔记

内容安全 防病毒 过滤技术 密码学