forked from imaNNeo/fl_chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
217 changes: 217 additions & 0 deletions
217
example/lib/presentation/samples/bar/bar_chart_hori_sample3.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import 'package:fl_chart_app/presentation/resources/app_resources.dart'; | ||
import 'package:fl_chart_app/util/extensions/color_extensions.dart'; | ||
import 'package:fl_chart/fl_chart.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class _BarChart extends StatelessWidget { | ||
const _BarChart(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BarChart( | ||
isHorizontal: true, | ||
BarChartData( | ||
barTouchData: barTouchData, | ||
titlesData: titlesData, | ||
borderData: borderData, | ||
barGroups: barGroups, | ||
gridData: const FlGridData(show: false), | ||
alignment: BarChartAlignment.spaceAround, | ||
maxY: 20, | ||
), | ||
); | ||
} | ||
|
||
BarTouchData get barTouchData => BarTouchData( | ||
enabled: false, | ||
touchTooltipData: BarTouchTooltipData( | ||
getTooltipColor: (group) => Colors.transparent, | ||
tooltipPadding: EdgeInsets.zero, rotateAngle: 270, //HERE MADE THE ROTATION OF THE TOOLTIP | ||
|
||
tooltipMargin: 8, | ||
getTooltipItem: ( | ||
BarChartGroupData group, | ||
int groupIndex, | ||
BarChartRodData rod, | ||
int rodIndex, | ||
) { | ||
return BarTooltipItem( | ||
rod.toY.round().toString(), | ||
const TextStyle( | ||
color: AppColors.contentColorCyan, | ||
fontWeight: FontWeight.bold, | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
|
||
Widget getTitles(double value, TitleMeta meta) { | ||
final style = TextStyle( | ||
color: AppColors.contentColorBlue.darken(20), | ||
fontWeight: FontWeight.bold, | ||
fontSize: 14, | ||
); | ||
String text; | ||
switch (value.toInt()) { | ||
case 0: | ||
text = 'Mn'; | ||
break; | ||
case 1: | ||
text = 'Te'; | ||
break; | ||
case 2: | ||
text = 'Wd'; | ||
break; | ||
case 3: | ||
text = 'Tu'; | ||
break; | ||
case 4: | ||
text = 'Fr'; | ||
break; | ||
case 5: | ||
text = 'St'; | ||
break; | ||
case 6: | ||
text = 'Sn'; | ||
break; | ||
default: | ||
text = ''; | ||
break; | ||
} | ||
return SideTitleWidget( | ||
axisSide: meta.axisSide, | ||
space: 4, | ||
child: Transform.rotate( | ||
// THIS TO ROTATE ALL THE TEXT | ||
angle: -1.5708, | ||
child: Text(text, style: style)), | ||
); | ||
} | ||
|
||
FlTitlesData get titlesData => FlTitlesData( | ||
show: true, | ||
bottomTitles: AxisTitles( | ||
sideTitles: SideTitles( | ||
showTitles: true, | ||
reservedSize: 30, | ||
getTitlesWidget: getTitles, | ||
), | ||
), | ||
leftTitles: const AxisTitles( | ||
sideTitles: SideTitles(showTitles: false), | ||
), | ||
topTitles: const AxisTitles( | ||
sideTitles: SideTitles(showTitles: false), | ||
), | ||
rightTitles: const AxisTitles( | ||
sideTitles: SideTitles(showTitles: false), | ||
), | ||
); | ||
|
||
FlBorderData get borderData => FlBorderData( | ||
show: false, | ||
); | ||
|
||
LinearGradient get _barsGradient => LinearGradient( | ||
colors: [ | ||
AppColors.contentColorBlue.darken(20), | ||
AppColors.contentColorCyan, | ||
], | ||
begin: Alignment.bottomCenter, | ||
end: Alignment.topCenter, | ||
); | ||
|
||
List<BarChartGroupData> get barGroups => [ | ||
BarChartGroupData( | ||
x: 0, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 8, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
BarChartGroupData( | ||
x: 1, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 10, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
BarChartGroupData( | ||
x: 2, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 14, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
BarChartGroupData( | ||
x: 3, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 15, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
BarChartGroupData( | ||
x: 4, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 13, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
BarChartGroupData( | ||
x: 5, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 10, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
BarChartGroupData( | ||
x: 6, | ||
barRods: [ | ||
BarChartRodData( | ||
toY: 16, | ||
gradient: _barsGradient, | ||
) | ||
], | ||
showingTooltipIndicators: [0], | ||
), | ||
]; | ||
} | ||
|
||
class BarChartHoriSample3 extends StatefulWidget { | ||
const BarChartHoriSample3({super.key}); | ||
|
||
@override | ||
State<StatefulWidget> createState() => BarChartHoriSample3State(); | ||
} | ||
|
||
class BarChartHoriSample3State extends State<BarChartHoriSample3> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return const AspectRatio( | ||
aspectRatio: 1.6, | ||
child: Padding( | ||
padding: EdgeInsets.symmetric(vertical: 10), | ||
child: _BarChart(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters