chart and filter

This commit is contained in:
Venba Team 2025-04-11 12:30:21 +05:30
parent 5ec46974a8
commit 8f04d7ec8f
2 changed files with 97 additions and 54 deletions

View File

@ -1853,15 +1853,43 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
print(
"Selected Filters before applying: $selectedFilters");
setState(() {
isLoading = true;
chartsData = originalTabChartsData;
cardData = originalTabCardData;
});
if (selectedFilters.every((filter) => filter['filter_data'].isEmpty)) {
setState(() {
isLoading = true;
});
selectedFilters.forEach((filter) {
filter["filter_data"].clear();
});
setState(() {
chartsData = List.from(originalTabChartsData);
cardData = List.from(originalTabCardData);
});
selectedFiltersStorage.clear();
formattedFilters = [];
applyFilters(context, filters, chartsData, cardData,
selectedFilters);
// selectedFiltersStorage = List.from(selectedFilters);
final locale =
ref.watch(localeProvider)?.languageCode ?? 'en';
print('locale22- $locale');
fetchChartData(
widget.dataSets,
locale,
tabWiseKpi, // Ensure you are passing the correct KPI here
formattedFilters // Pass the formatted filter data here
);
Navigator.pop(context);
} else {
setState(() {
isLoading = true;
chartsData = originalTabChartsData;
cardData = originalTabCardData;
});
applyFilters(context, filters, chartsData, cardData,
selectedFilters);
// selectedFiltersStorage = List.from(selectedFilters);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF92722A),

View File

@ -1616,7 +1616,7 @@ class ChartWidget extends StatelessWidget {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
physics: xAxisData.length > 4
physics: xAxisData.length == 5
? const NeverScrollableScrollPhysics() // Disable scrolling
: const AlwaysScrollableScrollPhysics(), // Enable scrolling
padding: const EdgeInsets.only(top: 10, left: 5),
@ -1681,30 +1681,25 @@ class ChartWidget extends StatelessWidget {
// ? yAxisLabels[groupIndex]
// : '';
// if (rod.toY == 0) return null;
if (rod.toY == 0) {
return BarTooltipItem(
'0', // Display "0" instead of hiding
const TextStyle(
color: Colors.black,
fontSize: 12,
fontWeight: FontWeight.w400,
),
);
final originalValue = rod.toY == 0.1 ? 0.0 : rod.toY;
String displayValue;
if (originalValue == 0.0) {
displayValue = '0'; // 🔥 clean and simple
} else {
displayValue = (chartConversion != null &&
chartConversion.isNotEmpty &&
number_format != null &&
chartConversion.isNotEmpty)
? formatNumberConversion(
originalValue,
chartConversion,
number_format,
)
: formatNumber(originalValue);
}
return BarTooltipItem(
(chartConversion != null &&
chartConversion.isNotEmpty &&
number_format != null &&
chartConversion.isNotEmpty)
? formatNumberConversion(
rod.toY,
chartConversion,
number_format,
) // If condition is true
: formatNumber(rod.toY),
displayValue,
const TextStyle(
color: Colors.black,
fontSize: 12,
@ -1837,31 +1832,51 @@ class ChartWidget extends StatelessWidget {
),
barGroups: List.generate(
xAxisData.length,
(index) => BarChartGroupData(
x: index,
barsSpace: 10,
barRods: [
BarChartRodData(
// toY: yAxisData[index],
toY: yAxisData[index] == 0
? 0.1
: yAxisData[index],
// toY: yAxisData[index] == 0
// ? 0.001
// : yAxisData[
// index], // gives a slight visible bar
// color: yAxisData[index] == 0
// ? Colors.grey
// : bodyColor,
color: bodyColor,
borderRadius: BorderRadius.circular(4),
width: 20,
),
],
showingTooltipIndicators: [0],
),
(index) {
final value = double.tryParse(yAxisData[index].toString()) ?? 0;
print('GGGGGG $value');
return BarChartGroupData(
x: index,
barsSpace: 10,
barRods: [
BarChartRodData(
toY: value == 0 ? 0.1 : value,
color: bodyColor,
borderRadius: BorderRadius.circular(4),
width: 20,
),
],
showingTooltipIndicators: [0],
);
},
),
// barGroups: List.generate(
// xAxisData.length,
// (index) => BarChartGroupData(
// x: index,
// barsSpace: 10,
// barRods: [
// BarChartRodData(
// // toY: yAxisData[index],
// toY: yAxisData[index] == 0
// ? 0.1
// : yAxisData[index],
// // toY: yAxisData[index] == 0
// // ? 0.001
// // : yAxisData[
// // index], // gives a slight visible bar
//
// // color: yAxisData[index] == 0
// // ? Colors.grey
// // : bodyColor,
// color: bodyColor,
// borderRadius: BorderRadius.circular(4),
// width: 20,
// ),
// ],
// showingTooltipIndicators: [0],
// ),
// ),
),
),
),