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

相关推荐
weixin_lynhgworld41 分钟前
剧本杀小程序系统开发:构建剧本杀社交新生态
小程序
说私域42 分钟前
基于定制开发开源 AI 智能名片 S2B2C 商城小程序的热点与人工下发策略研究
人工智能·小程序
weixin_lynhgworld43 分钟前
陪诊小程序系统开发:让就医不再是一件难事
小程序
是一碗螺丝粉15 小时前
拯救你的app/小程序审核!一套完美避开审核封禁的URL黑名单机制
前端·javascript·微信小程序
bug总结19 小时前
深入理解 uni-app 的 uni.createSelectorQuery()
uni-app
weixin_lynhgworld19 小时前
盲盒抽谷机小程序系统开发:从0到1的完整方法论
小程序
weixin_lynhgworld19 小时前
短剧小程序系统开发:赋能创作者,推动短剧艺术创新发展
小程序
真上帝的左手19 小时前
25. 移动端-uni-app
uni-app
编程猪猪侠19 小时前
基于Uni-app+vue3实现微信小程序地图固定中心点范围内拖拽选择位置功能(分步骤详解)
uni-app
小徐_23331 天前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
前端·uni-app·trae