uniapp__微信小程序使用秋云ucharts折线图双轴

1、子组件

javascript 复制代码
<template>
  <view class="charts-box">
    <qiun-data-charts 
      type="line"
      :opts="computedOpts"
      :chartData="chartData"
    />
  </view>
</template>

<script>
export default {
  props: {
    chartData: {
      type: Object,
      required: true
    },
    color: {
      type: Array,
      default: () => ["#1890FF", "#91CB74"]
    },
    yAxisMax: {
      type: Number,
      default: 5
    },
    yAxisMin: {
      type: Number,
      default: 0
    }
  },
  computed: {
    computedOpts() {
      // 在这里封装 opts,并根据父组件传入的 props 动态修改
      return {
        color: this.color, // 使用父组件传入的颜色
        padding: [15, 10, 0, 15],
        enableScroll: false,
        xAxis: {
          disableGrid: true,
		   rotateLabel: true
        },
        yAxis: {
          data: [
            {
              type: "value",
              position: "left",
			 
            },
            {
              type: "value",
              position: "right",
              min: this.yAxisMin, // 父组件传入的最小值
              max: this.yAxisMax  // 父组件传入的最大值
            }
          ]
        },
        extra: {
          line: {
            type: "straight",
            width: 2,
            activeType: "hollow"
          },
          tooltip: {
            legendShape: "circle"
          }
        }
      };
    }
  }
};
</script>

<style scoped>
.charts-box {
  width: 715rpx;
  height: 300px;
  margin-left: -51rpx;
}
</style>

2、父组件

javascript 复制代码
<lineecharts :chartData="chartData" :color="['#1890FF', '#91CB74']" :yAxisMax="10" :yAxisMin="0">
	getChartData() {
				const startTime = new Date();
				let timePoints = [];
				for (let i = 0; i < 6; i++) {
					const time = new Date(startTime.getTime() + i * 5000);
					const formattedTime = `${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`;
					timePoints.push(formattedTime);
				}
				setTimeout(() => {
					this.chartData = {
						categories: timePoints,
						series: [{
								name: "心率",
								data: [35, 8, 25, 37, 4, 20],
								index: 0
							},
							{
								name: "呼吸",
								data: [2, 4, 3, 1, 4, 1],
								index: 1
							}
						]
					};
				}, 100);
			
			},

双轴series: [{
name: "心率",
data: [35, 8, 25, 37, 4, 20],
index: 0
},
{
name: "呼吸",
data: [2, 4, 3, 1, 4, 1],
index: 1
}
]数据区分使用index

相关推荐
腾讯云云开发17 小时前
微信发布AI小程序成长计划:免费云开发资源+1亿token额度!
微信小程序·ai编程·小程序·云开发
iOS阿玮17 小时前
AppStore卡审依旧存在,预计下周将逐渐恢复常态!
uni-app·app·apple
开发加微信:hedian11617 小时前
推客与分销场景下的系统架构实践:如何支撑高并发与复杂业务规则
小程序
郑州光合科技余经理19 小时前
开发实战:海外版同城o2o生活服务平台核心模块设计
开发语言·git·python·架构·uni-app·生活·智慧城市
行走的陀螺仪19 小时前
在UniApp H5中,实现路由栈的持久化
前端·javascript·uni-app·路由持久化·路由缓存策略
影子打怪19 小时前
uniapp通过plus.geolocation.watchPosition获取的坐标格式转换
uni-app
游九尘19 小时前
在小程序中实现横竖屏切换的配置方法,实时监听页面宽度
小程序
weixin_lynhgworld19 小时前
[特殊字符]旧物焕新颜,二手变宝藏——小程序系统开发开启绿色生活新篇章[特殊字符]
小程序·生活
说私域19 小时前
小程序电商运营中“开源AI智能名片链动2+1模式S2B2C商城小程序”对培养“老铁”用户的重要性研究
人工智能·小程序·开源
忒可君19 小时前
2026新年第一篇:uni-app + AI = 3分钟实现数据大屏
前端·vue.js·uni-app