收藏
回答

条形图时间怎么搞?

之前那位好心大佬帮我写出来的能不能再给我一份,之前的不小心被我删了

最后一次编辑于  2021-02-22
回答关注问题邀请回答
收藏

4 个回答

  • 卢霄霄
    卢霄霄
    2021-02-22

    这会儿开发者工具抽风,没法发出来了。。直接贴代码吧

    js:
    const app = getApp()
    
    Page({
      data: {
        test: [1, 2, 3],
        start: 6,
        end: 24,
        list: [
          {
            label: "今天",
            values: [7, 8, 9, 20, 21]
          },
          {
            label: "昨天",
            values: [10, 11, 12, 13, 14]
          },
        ]
      },
    })
    
    wxml:
    <wxs module="util">
      function hasValue(values, value) {
        return values.indexOf(value) != -1
      }
      module.exports.hasValue = hasValue
    </wxs>
    <view class="title-column">
      <view class="title">时段</view>
      <view class="mark" wx:for="{{end-start+1}}" wx:key="$this">
        <view class="mark-start">
          <view class="mark-label">{{item+start}}</view>
          <view class="mark-line"></view>
        </view>
      </view>
    </view>
    <view class="value-column" wx:for="{{list}}" wx:key="label">
      <view class="title">{{item.label}}</view>
      <view class="value {{util.hasValue(item.values, hour+start)?'has-value':'not-has-value'}}" wx:for="{{end-start+1}}" wx:for-item="hour" wx:key="$this">
      </view>
    </view>
    
    wxss:
    .title-column {
      display: flex;
      height: 60rpx;
      line-height: 60rpx;
      font-size: 18rpx;
      border-bottom: 1px solid #333;
    }
    .title {
      width: 100rpx;
      flex-shrink: 0;
      text-align: center;
    }
    .mark {
      flex: 1 0 0;
      position: relative;
    }
    .mark-start {
      position: absolute;
      left: 0;
      width: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .mark-line {
      width: 1px;
      height: 4px;
      background-color: #333;
      position: absolute;
      bottom: 0;
    }
    .mark:nth-child(2n+1) .mark-label {
      opacity: 0;
    }
    .mark:nth-child(2n+1) .mark-line {
      height: 2px;
    }
    .value-column {
      display: flex;
      align-items: center;
      height: 40rpx;
      line-height: 40rpx;
      font-size: 18rpx;
    }
    .value {
      flex: 1 0 0;
      height: 30rpx;
    }
    .has-value {
      background-color: #aaa;
    }
    .not-has-value {
      background-color: red;
    }
    .value:last-child {
      background-color: transparent;
    }
    
    2021-02-22
    有用
    回复 7
    • 。。。
      。。。
      2021-02-22
      多谢
      2021-02-22
      回复
    • 。。。
      。。。
      2021-03-02
      大佬使用HTML制作下面的条形图能不能像小程序一样循环并且黄色部分可以设置
      2021-03-02
      回复
    • 卢霄霄
      卢霄霄
      2021-03-02回复。。。
      可以啊 稍微改动下就行了。。你可以的
      2021-03-02
      回复
    • 。。。
      。。。
      2021-03-02
      好的,谢谢
      2021-03-02
      回复
    • 。。。
      。。。
      2021-03-05回复卢霄霄
      能帮我看下wxs这段控制条形图的代码怎么写吗?
      2021-03-05
      回复
    查看更多(2)
  • 陈宇明
    陈宇明
    2021-02-22

    查看你的历史代码

    2021-02-22
    有用
    回复
  • 🇭  🇬 
    🇭  🇬 
    2021-02-22

    自己用CSS也可以写一套,不难

    2021-02-22
    有用
    回复 1
    • 。。。
      。。。
      2021-02-22
      有点难,小弟刚入行没多久
      2021-02-22
      回复
  • 睡前原谅一切
    睡前原谅一切
    2021-02-22

    你翻消息吖

    2021-02-22
    有用
    回复
登录 后发表内容
问题标签