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

相关推荐
百锦再9 小时前
抖音小程序开发全景透视:生态解析、技术架构与商业实践
人工智能·ai·微信小程序·小程序·架构·模型·抖音
低代码布道师13 小时前
互联网医院18:前端进阶——CSS“父相子绝”打造专业级卡片交互
前端·css·低代码·小程序·云开发
说私域14 小时前
开源活动报名AI智能客服AI智能名片预约服务小程序在精神服务中的应用场景研究
人工智能·小程序
计算机毕设指导617 小时前
基于微信小程序的家政服务与互助平台【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
wetyuo19 小时前
【随手记】uniapp + V3 使用TailwindCss3
uni-app·vue·css3·vite
说私域19 小时前
开源悬赏活动报名AI智能名片链动2+1模式商城小程序的应用与价值
人工智能·微信·小程序·开源
计算机毕设指导620 小时前
基于微信小程序的个性化漫画阅读推荐系统【源码文末联系】
java·python·微信小程序·小程序·tomcat·maven·intellij-idea
百锦再20 小时前
开发抖音小程序组件大全概述
人工智能·python·ai·小程序·aigc·notepad++·自然语言
Lucky小黄人1 天前
微信小程序开发常见报错
微信小程序·小程序
Stanford_11062 天前
【2026新年启程】学习之路,探索之路,技术之路,成长之路……都与你同行!!!
前端·c++·学习·微信小程序·排序算法·微信开放平台