哈哈,我现在去做app了,用的flutter,刚好做了两个图表,这里指写第一个图表,直接贴代码干就完了,如果有缘看到帮点个赞(#^.^#)
其他图,你需要更改为曲线,其他差不多

效果图:当前代码图片:

import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/gestures.dart';
import 'package:wisemedical/base/common_widget/dashed_rect.dart';
class MyLineChartIndex extends StatefulWidget {
// 传递过来的参数我删除了,不影响代码的执行,页面中的数据都是死的
@override
State createState() => _MyLineChartIndexState();
}
class _MyLineChartIndexState extends State<MyLineChartIndex> {
double touchedValue;
List weekDays = [];
bool showcir = false;
List<double> yValues = [];
@override
void initState() {
touchedValue = -1;
showcir = true;
weekDays = [
"2021-02-01",
"2021-03-01",
"2021-04-01",
"2021-05-01",
"2021-06-01",
"2021-07-01",
"2021-08-01"
];
yValues = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0];
super.initState();
}
@override
Widget build(BuildContext context) {
final List<int> showIndexes = yValues.asMap().keys.toList();
final lineBarsData = [
LineChartBarData(
isStepLineChart: false,
showingIndicators: showIndexes,
spots: yValues.asMap().entries.map((e) {
return FlSpot(e.key.toDouble(), e.value);
}).toList(),
isCurved: true,
barWidth: 2,
// dashArray: [30, 1],
colors: [
Color(0xFF22A3FD),
],
belowBarData: BarAreaData(
show: false,
colors: [
Colors.orange.withOpacity(0.5),
Colors.orange.withOpacity(0.0),
],
gradientColorStops: [0.1, 1.0],
gradientFrom: const Offset(0, 0),
gradientTo: const Offset(0, 1),
spotsLine: BarAreaSpotsLine(
show: true,
flLineStyle: FlLine(
color: Colors.blue,
strokeWidth: 3,
),
checkToShowSpotLine: (spot) {
if (spot.x == 0 || spot.x == 6) {
return false;
}
return true;
},
),
),
dotData: FlDotData(
show: true,
getDotPainter: (spot, percent, barData, index) {
if (index != weekDays.length - 1 && showcir) {
return FlDotCirclePainter(
radius: 1,
color: Color(0xFF22A3FD),
strokeWidth: 2,
strokeColor: Color(0xFF22A3FD));
} else {
return FlDotCirclePainter(
radius: 3,
color: Colors.white,
strokeWidth: 2,
strokeColor: Color(0xFF22A3FD),
);
}
},
// checkToShowDot: (spot, barData) {
// return spot.x != 0 && spot.x != 6;
// }
),
),
];
final tooltipsOnBa
2928



被折叠的 条评论
为什么被折叠?



