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

相关推荐
软件管理系统10 小时前
基于小程序的高校后勤报修管理系统
小程序
青春逝如流水11 小时前
微信小程序开发入门
微信小程序·小程序·入门
weixin_lynhgworld14 小时前
淘宝扭蛋机小程序:开启线上娱乐与购物的全新融合时代
小程序·娱乐
树欲静而风不止慢一点吧15 小时前
小米手环9应用/游戏开发快速入门
前端·javascript·小程序
游戏开发爱好者815 小时前
抓包工具有哪些?代理抓包、数据流抓包、拦截转发工具
android·ios·小程序·https·uni-app·iphone·webview
棒棒的唐16 小时前
vant小程序版弹窗穿透滚动的解决方案
小程序
翔云 OCR API16 小时前
NFC护照识读鉴伪解决方案-小程序/app端护照鉴伪
小程序
郑州光合科技余经理19 小时前
技术解析:如何打造适应多国市场的海外跑腿平台
java·开发语言·javascript·mysql·spring cloud·uni-app·php
前端 贾公子20 小时前
uniapp之实现拖拽排序
uni-app
禾高网络20 小时前
互联网医院定制|互联网医院|禾高互联网医院搭建
java·大数据·人工智能·小程序