barChartHorizontal method
Implementation
Widget barChartHorizontal({required List<ChartData> dados, Color? color, bool? isTransposed, String? numberFormatSymbol}) {
return SfCartesianChart(
margin: const EdgeInsets.all(20),
plotAreaBorderWidth: 0.5,
enableAxisAnimation: true,
isTransposed: isTransposed ?? false,
primaryXAxis: const CategoryAxis(
labelStyle: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 12,
),
labelsExtent: 120,
majorGridLines: MajorGridLines(width: 1),
isInversed: true,
),
primaryYAxis: NumericAxis(
majorGridLines: const MajorGridLines(width: 1),
numberFormat: NumberFormat.compactCurrency(symbol: numberFormatSymbol ?? ''),
minimum: 0,
rangePadding: ChartRangePadding.auto,
),
series: [
BarSeries<ChartData, String>(
dataSource: dados,
xValueMapper: (ChartData data, _) => Features.formatarTextoPrimeirasLetrasMaiusculas(data.nome),
yValueMapper: (ChartData data, _) => data.valor,
pointColorMapper: (ChartData data, _) => data.color ?? color,
width: 1,
spacing: 0.5,
borderWidth: 1,
borderColor: Colors.black,
borderRadius: const BorderRadius.all(Radius.circular(10)),
enableTooltip: true,
dataLabelMapper: (ChartData data, _) {
if (data.type == int) {
return '${numberFormatSymbol ?? ''}${Features.toFormatNumber(data.valor.toString(), qtCasasDecimais: 0)}';
} else {
return '${numberFormatSymbol ?? 'R\$ '}${Features.toFormatNumber(data.valor.toString())}';
}
},
dataLabelSettings: DataLabelSettings(
isVisible: true,
alignment: ChartAlignment.center,
textStyle: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 11,
),
labelAlignment: ChartDataLabelAlignment.auto,
angle: isTransposed ?? false ? 0 : 0,
),
),
],
);
}