127 lines
3.9 KiB
Dart
127 lines
3.9 KiB
Dart
import 'package:fl_chart/fl_chart.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:vbvs_app/common/util/FitTool.dart';
|
|
import 'package:vbvs_app/common/util/MyUtils.dart';
|
|
|
|
class ScatterPlotChart extends StatelessWidget {
|
|
final List<ScatterSpot> points;
|
|
final double xMin;
|
|
final double xMax;
|
|
final double yMin;
|
|
final double yMax;
|
|
final Color pointColor;
|
|
|
|
ScatterPlotChart({
|
|
required this.points,
|
|
required this.xMin,
|
|
required this.xMax,
|
|
required this.yMin,
|
|
required this.yMax,
|
|
required this.pointColor,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
const double interval = 400; // 默认间隔
|
|
|
|
return SizedBox(
|
|
child: ScatterChart(
|
|
ScatterChartData(
|
|
backgroundColor: Colors.transparent,
|
|
gridData: FlGridData(
|
|
show: true,
|
|
horizontalInterval: interval,
|
|
verticalInterval: interval,
|
|
getDrawingHorizontalLine: (value) {
|
|
return FlLine(
|
|
color: themeController.currentColor.sc4,
|
|
strokeWidth: 1.rpx,
|
|
dashArray: [5, 5], // 设置虚线 [实线长度, 空白长度]
|
|
);
|
|
},
|
|
getDrawingVerticalLine: (value) {
|
|
return FlLine(
|
|
color: themeController.currentColor.sc4,
|
|
strokeWidth: 1.rpx,
|
|
dashArray: [5, 5], // 设置虚线
|
|
);
|
|
},
|
|
),
|
|
titlesData: FlTitlesData(
|
|
show: true,
|
|
leftTitles: AxisTitles(
|
|
sideTitles: SideTitles(
|
|
showTitles: true,
|
|
reservedSize: 70.rpx,
|
|
interval: 400, // 强制 400 一个刻度
|
|
getTitlesWidget: (double value, TitleMeta meta) {
|
|
// 只显示 400 的倍数
|
|
if (value % 400 != 0) return Container();
|
|
|
|
return Padding(
|
|
padding: EdgeInsets.only(right: 14.rpx),
|
|
child: Text(
|
|
value.toStringAsFixed(0),
|
|
style: TextStyle(
|
|
fontSize: 18.rpx,
|
|
color: themeController.currentColor.sc4,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
bottomTitles: AxisTitles(
|
|
sideTitles: SideTitles(
|
|
showTitles: true,
|
|
getTitlesWidget: (double value, TitleMeta meta) {
|
|
// 只显示 400 的倍数
|
|
if (value % 400 != 0) return Container();
|
|
return Text(
|
|
value.toStringAsFixed(0),
|
|
style: TextStyle(
|
|
fontSize: 18.rpx,
|
|
color: themeController.currentColor.sc4,
|
|
),
|
|
);
|
|
},
|
|
interval: 400, // 强制间隔 400
|
|
),
|
|
),
|
|
rightTitles: AxisTitles(
|
|
sideTitles: SideTitles(showTitles: false),
|
|
),
|
|
topTitles: AxisTitles(
|
|
sideTitles: SideTitles(showTitles: false),
|
|
),
|
|
),
|
|
borderData: FlBorderData(
|
|
show: true,
|
|
border: Border.all(
|
|
color: themeController.currentColor.sc4,
|
|
width: 0.5,
|
|
),
|
|
),
|
|
scatterSpots: points.map((point) {
|
|
return ScatterSpot(
|
|
point.x,
|
|
point.y,
|
|
dotPainter: FlDotCirclePainter(
|
|
radius: 3.rpx,
|
|
color: pointColor,
|
|
),
|
|
);
|
|
}).toList(),
|
|
minX: xMin,
|
|
maxX: xMax,
|
|
minY: yMin,
|
|
maxY: yMax,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|