feat: Enhance tooltip behavior in ExpenseDonutChart to display formatted currency and percentage
This commit is contained in:
parent
9890fbaffe
commit
99f6c594b9
@ -381,13 +381,45 @@ class _ExpenseDonutChartState extends State<_ExpenseDonutChart> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
_tooltipBehavior = TooltipBehavior(
|
_tooltipBehavior = TooltipBehavior(
|
||||||
enable: true,
|
enable: true,
|
||||||
format: 'point.x: point.y',
|
builder: (dynamic data, dynamic point, dynamic series, int pointIndex,
|
||||||
color: Colors.blueAccent,
|
int seriesIndex) {
|
||||||
textStyle: const TextStyle(
|
final total = widget.data.report
|
||||||
color: Colors.white,
|
.fold<double>(0, (sum, e) => sum + e.totalApprovedAmount);
|
||||||
fontSize: 12,
|
final value = data.value as double;
|
||||||
fontWeight: FontWeight.w600,
|
final percentage = total > 0 ? (value / total * 100) : 0;
|
||||||
),
|
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
data.label,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(
|
||||||
|
Utils.formatCurrency(value),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${percentage.toStringAsFixed(1)}%',
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 10),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
animationDuration: 300,
|
animationDuration: 300,
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user