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( print(
"Selected Filters before applying: $selectedFilters"); "Selected Filters before applying: $selectedFilters");
setState(() { if (selectedFilters.every((filter) => filter['filter_data'].isEmpty)) {
isLoading = true; setState(() {
chartsData = originalTabChartsData; isLoading = true;
cardData = originalTabCardData; });
}); selectedFilters.forEach((filter) {
filter["filter_data"].clear();
});
setState(() {
chartsData = List.from(originalTabChartsData);
cardData = List.from(originalTabCardData);
});
selectedFiltersStorage.clear();
formattedFilters = [];
applyFilters(context, filters, chartsData, cardData, final locale =
selectedFilters); ref.watch(localeProvider)?.languageCode ?? 'en';
// selectedFiltersStorage = List.from(selectedFilters);
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( style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF92722A), backgroundColor: Color(0xFF92722A),

View File

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