我正在尝试在颤动应用程序中设计一个图表,该图表显示针对时间或日期绘制的数据(取决于按下按钮),但是,我遇到了一个问题,即图形标签文本相互碰撞。
我想知道是否有一种方法可以旋转 fl_chart 对象 LineChartData 中的文本以倾斜或垂直旋转显示日期或时间?
到目前为止,我的代码看起来像这样,图形的输出看起来像这样:
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:sembast/timestamp.dart';
import '../models/outcome.dart';
dynamic grapher() {
return Stack(
children: <Widget>[
AspectRatio(
aspectRatio: 1.70,
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(18),
),
color: Colors.black),
child: Padding(
padding: const EdgeInsets.only(
right: 18.0, left: 12.0, top: 24, bottom: 12),
child: LineChart(
mainData(),
),
),
),
),
],
);
}
LineChartData mainData() {
return LineChartData(
...
titlesData: FlTitlesData(
show: true,
bottomTitles: SideTitles(
showTitles: true,
reservedSize: 22,
textStyle: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16),
getTitles: (value) {
//return value.round().toString();
for (int i = 0; i <= outcomeList.length; i++) {
return outcomeList[i].recordedTime.toString();
}
},
margin: 8,
),
...
),
...
}
List<FlSpot> datapoints = [
FlSpot(0, outcomeList[0].value),
FlSpot(2.6, outcomeList[1].value),
FlSpot(4.9, outcomeList[2].value),
FlSpot(6.8, outcomeList[3].value),
FlSpot(8, outcomeList[4].value),
FlSpot(10, outcomeList[5].value),
];
List<Outcome> outcomeList = [
Outcome(name: 'mood', recordedTime: Timestamp.now(), value: 5.6),
Outcome(
name: 'mood',
recordedTime:
Timestamp.fromDateTime(DateTime.now().add(new Duration(hours: 1))),
value: 6.7),
Outcome(
name: 'mood',
recordedTime:
Timestamp.fromDateTime(DateTime.now().add(new Duration(hours: 2))),
value: 5.5),
Outcome(
name: 'mood',
recordedTime:
Timestamp.fromDateTime(DateTime.now().add(new Duration(hours: 3))),
value: 6.2),
Outcome(
name: 'mood',
recordedTime:
Timestamp.fromDateTime(DateTime.now().add(new Duration(hours: 4))),
value: 7.7),
Outcome(
name: 'mood',
recordedTime: Timestamp.fromDateTime(
DateTime.now().add(new Duration(hours: 5, minutes: 26))),
value: 6.4),
];