color and text width
This commit is contained in:
parent
7e67415c08
commit
b6fe1841aa
|
|
@ -54,6 +54,7 @@ class MyBarChart extends StatelessWidget {
|
||||||
|
|
||||||
final List<ChartData> data = ChartData.exampleData();
|
final List<ChartData> data = ChartData.exampleData();
|
||||||
final double _chartTextRotation = -1.57079633;
|
final double _chartTextRotation = -1.57079633;
|
||||||
|
final double _leftTextWidth = 70;
|
||||||
|
|
||||||
double get maxY => max(
|
double get maxY => max(
|
||||||
data.map((d) => d.gpa).reduce((a, b) => max(a, b)),
|
data.map((d) => d.gpa).reduce((a, b) => max(a, b)),
|
||||||
|
|
@ -72,9 +73,15 @@ class MyBarChart extends StatelessWidget {
|
||||||
return SideTitleWidget(
|
return SideTitleWidget(
|
||||||
angle: _chartTextRotation,
|
angle: _chartTextRotation,
|
||||||
axisSide: meta.axisSide,
|
axisSide: meta.axisSide,
|
||||||
|
child: SizedBox(
|
||||||
|
width: _leftTextWidth,
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerRight,
|
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(
|
.map((d) => BarChartGroupData(
|
||||||
x: data.indexOf(d),
|
x: data.indexOf(d),
|
||||||
barRods: [
|
barRods: [
|
||||||
BarChartRodData(toY: d.year.toDouble()),
|
BarChartRodData(toY: d.year.toDouble(), color: Colors.orange),
|
||||||
BarChartRodData(toY: d.gpa.toDouble())
|
BarChartRodData(toY: d.gpa.toDouble(), color: Colors.indigo)
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
@ -106,7 +113,7 @@ class MyBarChart extends StatelessWidget {
|
||||||
getTitlesWidget: _getBottomSideTitleWidget)),
|
getTitlesWidget: _getBottomSideTitleWidget)),
|
||||||
bottomTitles: AxisTitles(
|
bottomTitles: AxisTitles(
|
||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
reservedSize: 50,
|
reservedSize: _leftTextWidth + 20,
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
getTitlesWidget: _getLeftSideTitleWidget)),
|
getTitlesWidget: _getLeftSideTitleWidget)),
|
||||||
),
|
),
|
||||||
|
|
@ -128,8 +135,8 @@ class ChartData {
|
||||||
|
|
||||||
static List<ChartData> exampleData() {
|
static List<ChartData> exampleData() {
|
||||||
return [
|
return [
|
||||||
ChartData(name: "John", gpa: 2, year: 1),
|
ChartData(name: "John Doe", gpa: 2, year: 1),
|
||||||
ChartData(name: "Jane", gpa: 3, year: 2),
|
ChartData(name: "Jane Doe", gpa: 3, year: 2),
|
||||||
ChartData(name: "Doe", gpa: 4, year: 3),
|
ChartData(name: "Doe", gpa: 4, year: 3),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue