双列时间轴

9 篇文章 0 订阅
3 篇文章 0 订阅

1. 效果

 2. 代码

<template>
  <div class="Timeline">
    <div class="timeaxis">
      <div v-for="(item, i) in list" :key="i">
        <div class="timeaxis-box">
          <div class="timeaxis-box-line"></div>
          <div :class="['timeaxis-box-content', i % 2 === 0 ? 'up' : 'down']">
            <div>
              {{ item.firstContent }}
            </div>
            <div>
              <span>
                {{ item.title }}
              </span>
            </div>
            <div>
              {{ item.secondCeotent }}
            </div>
          </div>
          <div class="timeaxis-box-circle">
            {{ item.num }}
            <div :class="['arrow', i % 2 === 0 ? 'down' : 'up']"></div>
          </div>
          <div class="timeaxis-box-bootomText">
            <div class="text">{{ item.date }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
const list = [
  {
    title: "公司治理",
    firstContent:
      "三大航年报出炉2020年累计亏损逾370亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元",
    secondCeotent: "三大航年报出炉2020年累计亏损逾370",
    date: "2017-03-10",
    num: 1
  },
  {
    title: "公司治理2",
    firstContent: "三大航年报出炉2020年累计亏损逾370亿元",
    secondCeotent:
      "三大航年报出炉2020年累计亏损逾370亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元",
    date: "2017-03-11",
    num: 1
  },
  {
    title: "公司治理3",
    firstContent: "三大航年报出炉2020年累计亏损逾370",
    secondCeotent:
      "三大航年报出炉2020年累计亏损逾370亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元",
    date: "2017-03-12",
    num: 12
  },
  {
    title: "公司治理4",
    firstContent: "三大航年报出炉2020年累计亏损逾37亿元亿元亿元亿元亿元亿元亿元亿元亿元",
    secondCeotent: "三大航年报出炉2020年累计亏损逾370亿",
    date: "2017-03-13",
    num: 12
  },
  {
    title: "公司治理公司治理",
    firstContent: "三大航年报出炉2020年累计亏损逾",
    secondCeotent: "三大航年报出炉2020年累计亏损逾",
    date: "2017-03-14",
    num: 15
  },
  {
    title: "公司治理",
    firstContent:
      "三大航年报出炉2020年累计亏损逾370亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元亿元",
    secondCeotent: "三大航年报出炉2020年累计亏损逾370亿元",
    date: "2017-03-15",
    num: 7
  }
];
export default {
  name: "TimeAixs",
  data() {
    return {
      list
    };
  }
};
</script>

<style lang="less" scoped>
/* 面板的背景色 */
@boxBackGround: #756b67;
/* 圆点的半径 */
@circlRadius: 20px;
/* 箭头的半径 */
@arrowHeight: 10px;
/* 字体的颜色 */
@color: #fff;
/* 轴线的颜色 */
@axisColor: #c9cdd4;
/* 设置轴线居中(距离顶部的高度) */
@axisLineTop: @circlRadius / 2;
/* 两个点之间的间距 */
@pointSpace: 140px;
/* 面板的宽度 (*2代表一个面板的跨度为两个圆点间隔 -40则是连个面板之间的间隔)*/
@contentWidth: @pointSpace * 1.7;
/* 面板的高度 */
@contentHeight: 100px;
/* 轴向上方面板距离轴线的高度 */
@contentUpToBottom: 40px;
/* 轴向上方面板左偏移量 */
@contentUpToLeft: -20px;
/* 轴向下方面板距离轴线的高度 */
@contentDownToTop: 50px;
/* 轴向下方面板左偏移量 */
@contentDownToLeft: -(@pointSpace + 20);
/* 轴线下方的箭头距离point的距离 */
@arrowDownTop: @contentUpToBottom - 61;
/* 轴线上方的箭头距离point的距离 */
@arrowUpTop: @contentUpToBottom - 9;
.ellipsis {
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.before {
  content: "●";
  font-size: 14px;
  display: inline-block;
  height: 100%;
  float: left;
  margin-right: 10px;
  background-color: transparent;
}
.Timeline {
  position: relative;
  color: @color;
  font-size: 12px;
  .timeaxis {
    margin-left: 4em;
    display: flex;
    &-box {
      position: relative;
      width: @pointSpace;
      &-circle {
        position: relative;
        width: @circlRadius;
        height: @circlRadius;
        line-height: @circlRadius;
        border-radius: 50%;
        text-align: center;
        background: @boxBackGround;
        .arrow {
          position: absolute;
          border-left: @arrowHeight solid transparent;
          border-right: @arrowHeight solid transparent;
          height: 0;
          width: 0;
          &.down {
            border-bottom: @arrowHeight solid transparent;
            border-top: @arrowHeight solid @boxBackGround;
            top: @arrowDownTop;
          }
          &.up {
            border-top: @arrowHeight solid transparent;
            border-bottom: @arrowHeight solid @boxBackGround;
            top: @arrowUpTop;
          }
        }
      }
      &-content {
        position: absolute;
        display: flex;
        flex-direction: column;

        width: @contentWidth;
        height: @contentHeight;
        background: @boxBackGround;
        padding: 8px 10px;
        border-radius: 5px;
        font-size: 14px;
        font-weight: bold;
        row-gap: 10px;
        &.up {
          bottom: @contentUpToBottom;
          left: @contentUpToLeft;
        }
        &.down {
          top: @contentDownToTop;
          left: @contentDownToLeft;
        }
        div:nth-of-type(1) {
          .ellipsis();
          -webkit-line-clamp: 2; /* 这里是超出几行省略 */
          &::before {
            .before();
          }
        }
        div:nth-of-type(2) > span {
          display: inline;
          padding: 2px 5px;
          border-radius: 5px;
          background-color: #a19ea7;
          &::before {
            .before();
            content: " ";
            margin-right: 20px;
          }
        }
        div:last-child {
          .ellipsis();
          -webkit-line-clamp: 1;
          &::before {
            .before();
          }
        }
      }
      &-line {
        position: relative;
        border-bottom: 1px solid @axisColor;
        top: @axisLineTop;
      }
      &-bootomText {
        position: relative;
        .text {
          position: absolute;
          top: 2px;
          transform: translateX(-40%);
        }
      }
    }
    & > div:last-child {
      .timeaxis-box-line {
        border: none;
      }
    }
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用 `yyaxis` 函数来实现双坐标轴图。 假设你有一个时间序列 `t`,一个电压序列 `V`,和一个温度矩阵 `T`,其中每一列代表一组温度数据。可以按照以下步骤绘制双坐标轴图: 1. 创建一个新的 figure,并使用 `yyaxis left` 创建一个左侧的坐标轴。 ```matlab figure; yyaxis left; ``` 2. 绘制电压数据,使用 `plot` 函数。为了使电压数据与左侧坐标轴关联,需要在 `plot` 函数中添加 `'Parent'` 参数并将其设置为左侧坐标轴的句柄。 ```matlab plot(t, V, 'Parent', gca); ``` 3. 使用 `yyaxis right` 创建右侧的坐标轴,并通过 `ylim` 函数设置温度数据的纵坐标范围。 ```matlab yyaxis right; ylim([0 100]); % 假设温度数据的范围在 0-100 度之间 ``` 4. 使用 `plot` 函数分别绘制每组温度数据。为了使每组温度数据与右侧坐标轴关联,需要在 `plot` 函数中添加 `'Parent'` 参数并将其设置为右侧坐标轴的句柄。可以使用不同的颜色或线型来区分不同组的数据。 ```matlab hold on; % 保持图形窗口中已有的图形对象 for i = 1:size(T, 2) plot(t, T(:, i), 'Parent', gca, 'Color', rand(1, 3), 'LineStyle', '-'); end ``` 5. 添加图例和标签。可以使用 `legend` 函数添加图例,并使用 `xlabel` 和 `ylabel` 函数添加横轴和纵轴标签。 ```matlab legend(['Voltage'; cellstr(num2str((1:size(T, 2))', 'Temp%d'))]); xlabel('Time (s)'); ylabel('Voltage (V) / Temperature (\circC)'); ``` 完整的代码示例如下: ```matlab t = linspace(0, 10, 100); V = sin(t); T = rand(100, 6) * 100; figure; yyaxis left; plot(t, V, 'Parent', gca); yyaxis right; ylim([0 100]); hold on; for i = 1:size(T, 2) plot(t, T(:, i), 'Parent', gca, 'Color', rand(1, 3), 'LineStyle', '-'); end legend(['Voltage'; cellstr(num2str((1:size(T, 2))', 'Temp%d'))]); xlabel('Time (s)'); ylabel('Voltage (V) / Temperature (\circC)'); ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

好喝的西北风

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

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

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

打赏作者

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

抵扣说明:

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

余额充值