多选下拉数据,生成对应的Echarts图表数据

业务需求,要根据选中的下拉数据字段,生成对应的折线数据,取消对应的不显示对应的数据展示。
1.功能演示
在这里插入图片描述

<template>
  <div class="DauUse">
              <div class="absolute" style="left:760px;top:760px;width:190px;height:36px;border: 1px solid rgb(76, 202, 253);border-radius: 4px;">
              <el-select v-model="information"  multiple clearable  :collapse-tags="true" @change="changewd" style="width:190px;height:36px;line-height:36px;">
                <el-option
                  v-for="item in fangdianList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
  <div ref="testChart" style="width: 818px;height: 245px;"></div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
          fangdianList:[
          {
          value: '盘管温度',
          label: '盘管温度'
        }, {
          value: '冷凝温度',
          label: '冷凝温度'
        }, {
          value: '室内温度',
          label: '室内温度'
        } ],
          information:[],
          optionsChart :'',
      }
    }methods: {
     getData(){
     //初始化图表
     this.listChart = echarts.init(this.$refs.testChart)this.optionsChart = {
              tooltip: {
                trigger: "axis",
                axisPointer: {
                  type: "cross",
                  lineStyle: {
                    color: "#999", //设置提示框线条颜色
                  },
                  crossStyle: {
                    color: "#999",
                  },
                },
              },
              legend: {
                data: ["盘管温度"],
                top: 0,
                textStyle: { color: "#FFF" },
              },
              grid: {
                top: "10%",
                left: "4%",
                right: "2%",
                bottom: "30",
              },
              xAxis: {
                type: "category",
                boundaryGap: false,
                data: [
                  "00:00",
                  "02:00",
                  "04:00",
                  "06:00",
                  "08:00",
                  "10:00",
                  "12:00",
                  "14:00",
                  "16:00",
                  "18:00",
                  "20:00",
                  "22:00",
                  "24:00",
                ],
                splitLine: {
                  show: false,
                },
                axisLabel: {
                  show: true,
                  textStyle: {
                    color: "#4CCAFD",
                  },
                },
              },
              yAxis: {
                type: "value",
                axisLine: {
                  show: false,
                },
                splitLine: {
                  show: false,
                },
                axisLabel: {
                  show: true,
                  textStyle: {
                    color: "#4CCAFD",
                  },
                },
              },
              dataZoom: [
                {
                  type: "inside",
                  start: 0,
                  end: 30,
                },
                {
                  start: 0,
                  end: 10,
                },
              ],
              series: [
                {
                  name: "盘管温度",
                  type: "line",
                  smooth: true,
                  data: [44, 46, 31, 33, 50, 49, 42, 39, 40, 38],
                  areaStyle: {
                    color: {
                      type: "linear",
                      x: 0,
                      y: 0,
                      x2: 0,
                      y2: 1,
                      colorStops: [
                        {
                          offset: 0,
                          color: "rgba(76, 202, 253, 0.5)", // 0% 处的颜色
                        },
                        {
                          offset: 1,
                          color: "rgba(76, 202, 253, 0)", // 100% 处的颜色
                        },
                      ],
                      global: false, // 缺省为 false
                    },
                  },
                },
              ],
            };
          }
          // 使用刚指定的配置项和数据显示图表。
          this.listChart.setOption(this.optionsChart);
          //请求到的数据,模拟拿到下拉菜单数据
           this.$axios({}).then(res => {
              // 下拉初始赋值第一条数据
              this.zdValue = this.zhandianList[0].label
              this.information = [this.fangdianList[0].value]
          })
     }// 温度触发事件
        changewd(e){
          // 模拟数据
          const listData =[
              {
                  name: '盘管温度',
                  type: 'line',
                  smooth: true,
                  data: [44, 46, 31, 33, 50, 49, 42, 39, 40, 38],
                  areaStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: 'rgba(76, 202, 253, 0.5)', // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: 'rgba(76, 202, 253, 0)', // 100% 处的颜色
                      },
                    ],
                    global: false, // 缺省为 false
                  },
              },                  
              },
              {
                  name: '冷凝温度',
                  type: 'line',
                  smooth: true,
                  data: [36, 47, 45, 31, 34, 41, 49, 30, 48, 43],
                  areaStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: 'rgba(76, 202, 253, 0.5)', // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: 'rgba(76, 202, 253, 0)', // 100% 处的颜色
                      },
                    ],
                    global: false, // 缺省为 false
                  },
              },                  
              },
              {
                  name: '室内温度',
                  type: 'line',
                  smooth: true,
                  data: [35, 46, 50, 47, 33, 40, 39, 44, 38, 42],
                  areaStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: 'rgba(76, 202, 253, 0.5)', // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: 'rgba(76, 202, 253, 0)', // 100% 处的颜色
                      },
                    ],
                    global: false, // 缺省为 false
                  },
              },                  
              },
          ]
          const data=[];  //循环的series数据
          const legendList=[]; //循环的legend数据
          //循环对比e选中的数据名字和模拟数据中的name相同时push到数组中
          for (let i = 0; i < e.length; i++) {
            for (let j = 0; j < listData.length; j++) {
              // 相同条件名字的push到数组中
              if (e[i] == listData[j].name) {
                data.push(listData[j]);
                legendList.push(listData[j].name)
              }
            }
          }
          //赋值
          this.optionsChart.series = data
          this.optionsChart.legend.data = legendList
          //图表刷新变化
          this.listChart.setOption(this.optionsChart,true);
          }     
  }
</script>```

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Echarts是一个基于JavaScript的开源可视化库,它提供了丰富的图表类型和交互功能。其中,地图是Echarts中的一个重要组件,可以用来展示各种地理数据。在Echarts地图中,可以通过设置selectedMode属性来实现选中效果。具体来说,可以设置为single(单选)、multiple(多选)或false(不可选中)。同时,可以通过dispatchAction方法来触发选中效果,例如在鼠标移动或点击事件中使用。在选中效果中,可以设置选中的系列和数据索引,从而实现对地图上特定区域的高亮显示。 下面是一个示例代码,用于实现Echarts地图的选中效果: ``` option = { tooltip: { trigger: 'item', formatter: '{b}' }, series: [ { name: '中国', type: 'map', mapType: 'china', selectedMode: 'multiple', // 多选 label: { normal: { show: true }, emphasis: { show: true } }, data:[ { name:'广东', selected:true // 默认选中 } ] } ] }; // 选中效果 let index = 0; charts.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: 0, }); charts.on('mouseover', function(e) { if (e.dataIndex != index) { charts.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: index, }); } }); charts.on('mouseout', function(e) { index = e.dataIndex; charts.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: e.dataIndex, }); }); charts.on("click", function(e) { if (e.dataIndex != index) { charts.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: index, }); } index = e.dataIndex; charts.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: e.dataIndex, }); }); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值