当前位置: 首页 > news >正文

秋云 ucharts echarts 高性能跨全端图表组件导入

 上边的图表内容为随意填写

先从秋云 ucharts echarts 高性能跨全端图表组件 - DCloud 插件市场中安装插件

导入要用的文件中

父组件代码

<template>
  <view class="container">
    <view class="change">
      <view class="header">
        <text class="title">体重趋势</text>
      </view>
      <view class="tabs">
        <button @click="updateInterval(7)" :class="{ active: interval === 7 }">7天</button>
        <button @click="updateInterval(30)" :class="{ active: interval === 30 }">30天</button>
        <button @click="updateInterval(60)" :class="{ active: interval === 60 }">60天</button>
      </view>
      <view class="content">
        <!-- 通过 :chart-data 将数据传递给子组件 -->
        <weight-chart :chart-data="chartData" />
      </view>
    </view>
   </view>
</template>
<script setup>
import { ref } from 'vue';
import WeightChart from '../../components/WeightChart.vue'; // 确保路径正确

const interval = ref(7);
const chartData = ref({});

const updateInterval = (days) => {
  interval.value = days;
  fetchChartData(days);
};

const fetchChartData = (days) => {
  setTimeout(() => {
    const categories = [];
    const series = [];
    for (let i = 0; i < days; i++) {
      categories.push(`第${i + 1}天`);
      series.push(Math.random() * 10 + 35); // 随机生成体温数据
    }
    chartData.value = {
      categories,
      series: [
        {
          name: '体温',
          data: series
        }
      ]
    };
  }, 500);
};

// 初始化图表数据
fetchChartData(interval.value);
</script>
<style scoped>
.container {
  padding: 16px;
  background-color: #f8f8f8;
}
.change {
  margin-top: 20px;
  border: none; /* 边框 */
  border-radius: 10px; /* 圆角 */
  background-color: white;
  padding: 10px;
}
.header {
  margin-bottom: 20px;
}
.title {
  font-size: 20px;
  font-weight: bold;
}
.tabs {
  display: flex;
  margin-bottom: 20px;
  width: 80%;
  font-size: 15px;
  height: 40px;
}
button {
  flex: 1;
  padding: 2px;
  margin-right: 5px;
  background-color: #f0f0f0;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}
button.active {
  background-color: #007aff;
  color: white;
}
.content {
  width: 100%;
  height: 300px;
  background-color: whitesmoke;
  border-radius: 10px;
  overflow: hidden;
}
</style>

子组件WeightChart.vue静态折线图代码

<template>
  <view class="charts-box">
    <qiun-data-charts type="line" :chart-data="chartData" />
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import qiunDataCharts from '@/uni_modules/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue';

const chartData = ref({});

const getServerData = () => {
  setTimeout(() => {
    const res = {
      categories: ['2016', '2017', '2018', '2019', '2020'],
      series: [
        {
          name: '目标值',
          data: [35, 36, 31, 33, 13]
        },
        {
          name: '完成量',
          data: [18, 27, 21, 24, 6]
        }
      ]
    };
    chartData.value = res;
  }, 500);
};

onMounted(() => {
  getServerData();
});
</script>

<style scoped>
.charts-box {
  width: 100%;
  height: 300px;
}
</style>

相关文章:

  • P1443 马的遍历(BFS)
  • 企业日常工作中常用的 Linux 操作系统命令整理
  • Vue 与 Element UI 深度探秘:从 Array.isArray 到动态绑定的技术之旅!✨
  • HTML 表单 (form) 的作用解释
  • 【STM32F103ZET6——库函数】11.捕获红外信号
  • Linux基本操作指令1
  • WPS工具栏添加Mathtype加载项
  • 【网络】IP地址的分类
  • 兰亭妙微设计分享:解锁UI设计新趋势:界面设计色彩与布局秘籍
  • es 慢查询引起 cpu报警处理方法
  • 若依分页的逻辑分析
  • nodejs使用WebSocket实现聊天效果
  • 蓝桥杯 Excel地址
  • ubuntu22.04安装P104-100一些经验(非教程)
  • 【单片机通信技术】串口通信的几种方式与比较,详细解释SPI通信
  • 蓝桥杯2024年第十五届省赛真题-传送阵
  • 机器学习数学基础:42.AMOS 结构方程模型(SEM)分析的系统流程
  • 基于 STC89C52 的 8x8 点阵显示数字
  • DeepSeek私有化部署5:openEuler 24.03-LTS-SP1安装docker
  • 7. 机器人记录数据集(具身智能机器人套件)
  • 降水较常年同期少五成,安徽四大水利工程调水超11亿方应对旱情
  • 李成钢:近期个别经济体实施所谓“对等关税”,严重违反世贸组织规则
  • 人形机器人灵犀X2掌握新技能:有了“内心戏”,还会拳脚功夫
  • 河南信阳:对违规吃喝问题不遮丑不护短,露头就打、反复敲打
  • 全国人大常委会今年将初次审议检察公益诉讼法
  • 知名猎头公司创始人兼首席执行官庄华因突发疾病逝世,享年62岁