color and text width

This commit is contained in:
Andrei Stoica 2024-11-14 14:00:43 -05:00
parent 7e67415c08
commit b6fe1841aa
1 changed files with 15 additions and 8 deletions

View File

@ -54,6 +54,7 @@ class MyBarChart extends StatelessWidget {
final List<ChartData> data = ChartData.exampleData();
final double _chartTextRotation = -1.57079633;
final double _leftTextWidth = 70;
double get maxY => max(
data.map((d) => d.gpa).reduce((a, b) => max(a, b)),
@ -72,9 +73,15 @@ class MyBarChart extends StatelessWidget {
return SideTitleWidget(
angle: _chartTextRotation,
axisSide: meta.axisSide,
child: SizedBox(
width: _leftTextWidth,
child: Align(
alignment: Alignment.centerRight,
child: Text(data[x.floor()].name),
child: Text(
data[x.floor()].name,
overflow: TextOverflow.ellipsis,
),
),
),
);
}
@ -84,8 +91,8 @@ class MyBarChart extends StatelessWidget {
.map((d) => BarChartGroupData(
x: data.indexOf(d),
barRods: [
BarChartRodData(toY: d.year.toDouble()),
BarChartRodData(toY: d.gpa.toDouble())
BarChartRodData(toY: d.year.toDouble(), color: Colors.orange),
BarChartRodData(toY: d.gpa.toDouble(), color: Colors.indigo)
],
))
.toList();
@ -106,7 +113,7 @@ class MyBarChart extends StatelessWidget {
getTitlesWidget: _getBottomSideTitleWidget)),
bottomTitles: AxisTitles(
sideTitles: SideTitles(
reservedSize: 50,
reservedSize: _leftTextWidth + 20,
showTitles: true,
getTitlesWidget: _getLeftSideTitleWidget)),
),
@ -128,8 +135,8 @@ class ChartData {
static List<ChartData> exampleData() {
return [
ChartData(name: "John", gpa: 2, year: 1),
ChartData(name: "Jane", gpa: 3, year: 2),
ChartData(name: "John Doe", gpa: 2, year: 1),
ChartData(name: "Jane Doe", gpa: 3, year: 2),
ChartData(name: "Doe", gpa: 4, year: 3),
];
}