ECharts年月日切换图表

效果:
在这里插入图片描述

  <div class="w30LFwid bgs mt15"> 
   <h3 class="totalt_title"> <span class="titleIcon"> <em></em> <em></em> <em></em> </span> 社区参与人数 </h3> 
   <div class="w30sTab"> 
    <ul class="tabULLF1">
      /
     <li data-id="year" class="activeli"></li>/ 
     <li data-id="mon"></li>/ 
     <li data-id="day"></li>/ 
    </ul> 
   </div> 
   <div id="dataJoinNUM" style="width: 600px;height: 250px;overflow: visible;"></div> 
  </div>
.w30LFwid {
    width: 100%;
    height: 300px;
    position: relative;
}
.w30LFwid::before{
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  right: 3px;
  bottom: 3px;
  background: #082255;
  z-index: 0;
}
.bgs {
    box-shadow: rgba(82, 255, 226, 0.23) 0px 0px 9px 0px inset;
    border-radius: 3px;
    background: linear-gradient(to left, rgb(0, 205, 162), rgb(0, 205, 162)) left top / 3px 9px no-repeat, linear-gradient(rgb(0, 205, 162), rgb(0, 205, 162)) left top / 9px 3px no-repeat, linear-gradient(to left, rgb(0, 205, 162), rgb(0, 205, 162)) right top / 3px 9px no-repeat, linear-gradient(rgb(0, 205, 162), rgb(0, 205, 162)) right top / 9px 3px no-repeat, linear-gradient(to left, rgb(0, 205, 162), rgb(0, 205, 162)) left bottom no-repeat, linear-gradient(rgb(0, 205, 162), rgb(0, 205, 162)) left bottom no-repeat, linear-gradient(to left, rgb(0, 205, 162), rgb(0, 205, 162)) right bottom no-repeat, linear-gradient(to left, rgb(0, 205, 162), rgb(0, 205, 162)) right bottom no-repeat;
}
.mt15 {
    margin-top: 15px;
}
totalt_title {
  height: 38px;
  line-height: 38px;
  padding: 0 45px;
  display: block;
  /* background-color: #1c41d7; */
  color: #ffffff;
  font-size: 20px;
  letter-spacing: 0.15em;
  position: relative;
  /* background: #0b06246e; */
  /* background: linear-gradient(to left,#0b06246e,#0b062400); */
  /* border-left: 5px solid #12AAE3; */
}
.titleIcon {
  display: flex;
  align-items: center;
  position: absolute;
  left: 15px;
  top: 0;
  bottom: 0;
  width: 20px;
}
.titleIcon em {
  width: 3px;
  display: inline-flex;
  margin: 0 2px;
  border-radius: 10px;
}
.titleIcon em:nth-child(1) {
  height: 10px;
  background-color: rgba(0, 205, 162, 0.3);

}
.titleIcon em:nth-child(2) {
  height: 14px;
  background-color: rgba(0, 205, 162, 0.5);
}
.titleIcon em:nth-child(3) {
  height: 16px;
  background-color: rgba(0, 205, 162, 1);
}
.w30sTab {
  position: absolute;
  right: 20px;
  top: 15px;
}
.tabULLF,
.tabULLF1 {
  display: flex;
  color: #ffffff;
  font-size: 16px;
}
.tabULLF li,
.tabULLF1 li {
  padding: 0 7px;
  color: #13E8E9;
  cursor: pointer;
}
.activeli {
  color: #082255 !important;
  background: #fff;
  border-radius: 10px;
}
.tabULLF li:hover,
.tabULLF1 li:hover {
  background: #fff;
  color: #082255;
  border-radius: 10px;
}
function socialNum() {
  let RankData = {
    title: '参与总量',
    xname: '(数量)',
    yearRank: {
      name: '年',
      ydata: ['住宅小区'],
      xdata: [666]
    },
    monthRank: {
      name: '月',
      ydata: ['住宅小区'],
      xdata: [200]
    },
    dayRank: {
      name: '日',
      ydata: ['住宅小区', '希望小区'],
      xdata: [90, 100]
    }
  }
  let xRankData = RankData.yearRank.xdata,
  yRankData = RankData.yearRank.ydata;
  // 默认显示的数据
  myChartsRankList(dataJoinNUM, RankData.title, RankData.xname, yRankData, xRankData)

  $(".tabULLF1 li").click(function() {
    $(this).addClass("activeli").siblings().removeClass("activeli");
    if ($(this).data("id") == "year") {
      xRankData = RankData.yearRank.xdata;
      yRankData = RankData.yearRank.ydata;
      myChartsRankList(dataJoinNUM, RankData.title, RankData.xname, yRankData, xRankData)
    } else if ($(this).data("id") == "mon") {
      xRankData = RankData.monthRank.xdata;
      yRankData = RankData.monthRank.ydata myChartsRankList(dataJoinNUM, RankData.title, RankData.xname, yRankData, xRankData)
    } else if ($(this).data("id") == "day") {
      xRankData = RankData.dayRank.xdata;
      yRankData = RankData.dayRank.ydata myChartsRankList(dataJoinNUM, RankData.title, RankData.xname, yRankData, xRankData)
    }
  })
}
socialNum();
// 柱状图
function myChartsRankList(id, title, xname, yData, xData) {
  const myChartsRankList = echarts.init(id) myChartsRankList.setOption({
    title: {
      text: title,
      x: 'center',
      textStyle: {
        color: '#fff',
        fontSize: 14
      }
    },
    tooltip: {
      trigger: 'axis',
      formatter: "{b} <br> 数量: {c}"
    },
    grid: {
      left: '2%',
      right: '8%',
      bottom: '1%',
      top: '8%',
      containLabel: true
    },
    xAxis: {
      show: true,
      name: xname,
      splitLine: {
        show: false
      },
      type: 'value',
      min: 0,
      axisLine: {
        show: true,
        lineStyle: {
          color: '#fff'
        }
      }
    },
    yAxis: {
      splitLine: {
        show: false
      },
      type: 'category',
      data: yData,
      axisLine: {
        lineStyle: {
          color: '#fff'
        }
      },
      axisLabel: {
        show: true,
        interval: 0,
        rotate: 0,
        margin: 10,
        inside: false,
        textStyle: {
          //color: '#fff',
          fontWeight: '10'
        }
      }
    },
    series: [{
      type: 'bar',
      barWidth: '7',
      label: {
        normal: {
          show: true,
          // formatter: '{c}',
          formatter: function(v) {
            var val = v.data;
            if (val == 0) {
              return '';
            }
            return val;
          },
          color: '#fff'
        }
      },
      itemStyle: {
        emphasis: {
          barBorderRadius: 7
        },
        normal: {
          barBorderRadius: 50,
          color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
            offset: 0,
            color: '#0AF8EB'
          },
          {
            offset: 1,
            color: '#B055F8'
          }
          ])
        }
      },
      data: xData
    }]
  })
}
  • 8
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在echarts柱状图中添加年月日选择下拉框,你需要使用JavaScript和HTML来创建一个下拉框,并且使用echarts的API来获取选定的日期值,然后更新柱状图的数据。以下是一个简单的实现方式: 1. 首先,在HTML文件中创建一个下拉框,用于选择日期: ``` <label for="date-select">选择日期:</label> <select id="date-select"> <option value="20220101">202201月01日</option> <option value="20220102">202201月02日</option> <option value="20220103">202201月03日</option> <!-- 添加更多日期选项 --> </select> ``` 2. 然后,在JavaScript文件中使用echarts的API来获取选定的日期值,并更新柱状图的数据: ``` // 获取下拉框元素 var dateSelect = document.getElementById('date-select'); // 监听下拉框变化事件 dateSelect.addEventListener('change', function() { // 获取选中的日期值 var selectedDate = dateSelect.value; // 更新柱状图数据 var newData = getNewData(selectedDate); myChart.setOption({ series: [{ data: newData }] }); }); // 自定义函数,用于根据选定的日期值获取新的柱状图数据 function getNewData(selectedDate) { // 在这里根据选定的日期值获取新的数据 // 返回一个包含新数据的数组 } ``` 在自定义函数 `getNewData` 中,你需要根据选定的日期值来获取新的柱状图数据。你可以使用AJAX请求从服务器获取数据,或者使用本地数据进行计算。返回一个包含新数据的数组,然后使用 `setOption` 方法更新柱状图的数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

起伏羊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值