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

相关推荐
中犇科技1 天前
2026商城APP开发公司 TOP5(电商垂直版)
uni-app
扁豆的主人1 天前
Uniapp如何构建和部署
uni-app
小羊Yveesss1 天前
2026年知识付费小程序多少钱一个?
小程序
hhzz1 天前
Uniapp项目中解决一个比较典型的图标渲染问题:原生 tabBar(pages.json 里配置的那种)
uni-app·json
一只皮卡皮卡丘1 天前
微信小程序tab页苹果显示安卓不显示的问题
微信小程序·小程序
六月的可乐1 天前
【干货】小程序虚拟瀑布流探索小结
前端·react.js·小程序
小徐_23332 天前
Wot UI 2.1.0 发布:ConfigProvider 全局配置能力升级
前端·uni-app
前端 贾公子2 天前
小程序蓝牙打印探索与实践(上)
小程序
拙慕JULY2 天前
小程序返回 base64 文件报错
开发语言·javascript·小程序
dh131222505252 天前
按月季度销售业绩核算小程序
小程序·销售小程序·绩效小程序·业绩统计小程序·业绩核算小程序