更新
This commit is contained in:
100
lib/pages/sleep_report/chart/SleepRadarChart.dart
Normal file
100
lib/pages/sleep_report/chart/SleepRadarChart.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
|
||||
class SleepRadarChart extends StatelessWidget {
|
||||
final Map<String, double> today;
|
||||
final Map<String, double> yesterday;
|
||||
|
||||
const SleepRadarChart({
|
||||
Key? key,
|
||||
required this.today,
|
||||
required this.yesterday,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
// 雷达图
|
||||
_buildRadarChart(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRadarChart() {
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.3,
|
||||
child: RadarChart(
|
||||
RadarChartData(
|
||||
dataSets: [
|
||||
// 今日数据
|
||||
RadarDataSet(
|
||||
dataEntries: [
|
||||
RadarEntry(value: today['type1']!), // 呼吸暂停
|
||||
RadarEntry(value: today['type2']!), // 入睡时间
|
||||
RadarEntry(value: today['type3']!), // 离床次数
|
||||
RadarEntry(value: today['type4']!), // 深睡比例
|
||||
RadarEntry(value: today['type5']!), // 睡眠时长
|
||||
],
|
||||
borderColor: stringToColor("#00C1AA"),
|
||||
borderWidth: 2,
|
||||
fillColor: Colors.transparent,
|
||||
entryRadius: 0,
|
||||
),
|
||||
// 昨日数据
|
||||
RadarDataSet(
|
||||
dataEntries: [
|
||||
RadarEntry(value: yesterday['type1']!), // 呼吸暂停
|
||||
RadarEntry(value: yesterday['type2']!), // 入睡时间
|
||||
RadarEntry(value: yesterday['type3']!), // 离床次数
|
||||
RadarEntry(value: yesterday['type4']!), // 深睡比例
|
||||
RadarEntry(value: yesterday['type5']!), // 睡眠时长
|
||||
],
|
||||
borderColor: stringToColor("#FFD251"),
|
||||
borderWidth: 2,
|
||||
fillColor: Colors.transparent,
|
||||
entryRadius: 0,
|
||||
),
|
||||
],
|
||||
radarBackgroundColor: stringToColor("#343844"),
|
||||
radarBorderData:
|
||||
BorderSide(color: themeController.currentColor.sc4, width: 1),
|
||||
radarShape: RadarShape.polygon,
|
||||
titlePositionPercentageOffset: 0.2,
|
||||
titleTextStyle: TextStyle(
|
||||
fontSize: AppConstants().normal_text_fontSize,
|
||||
color: themeController.currentColor.sc3),
|
||||
getTitle: (index, angle) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return RadarChartTitle(text: '呼吸暂停');
|
||||
case 1:
|
||||
return RadarChartTitle(text: '入睡时间');
|
||||
case 2:
|
||||
return RadarChartTitle(text: '离床次数');
|
||||
case 3:
|
||||
return RadarChartTitle(text: '深睡比例');
|
||||
case 4:
|
||||
return RadarChartTitle(text: '睡眠时长');
|
||||
default:
|
||||
return const RadarChartTitle(text: '');
|
||||
}
|
||||
},
|
||||
tickCount: 5,
|
||||
ticksTextStyle:
|
||||
const TextStyle(color: Colors.transparent, fontSize: 10),
|
||||
// ticksColor: Colors.grey.shade300,
|
||||
gridBorderData: BorderSide(color: Colors.transparent, width: 1),
|
||||
tickBorderData:
|
||||
BorderSide(color: themeController.currentColor.sc4, width: 1),
|
||||
),
|
||||
swapAnimationDuration: const Duration(milliseconds: 400),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user