From 28a6e169eb48104b0e21b7adc3430f5ff551e5bb Mon Sep 17 00:00:00 2001 From: venbaittech Date: Thu, 3 Apr 2025 17:01:24 +0530 Subject: [PATCH] chart bug fix --- android/app/build.gradle | 4 +- .../Screens/charts/widgets/chart_widget.dart | 75 +++++++++++++++++-- pubspec.lock | 40 ++++++---- pubspec.yaml | 4 +- 4 files changed, 96 insertions(+), 27 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 4563361f..33af32b7 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -20,12 +20,12 @@ if (project.hasProperty('google-services.json')) { def flutterVersionCode = localProperties.getProperty("flutter.versionCode") if (flutterVersionCode == null) { - flutterVersionCode = "44" + flutterVersionCode = "47" } def flutterVersionName = localProperties.getProperty("flutter.versionName") if (flutterVersionName == null) { - flutterVersionName = "1.0.43" + flutterVersionName = "1.0.46" } def keystorePropertiesFile = rootProject.file("key.properties") diff --git a/lib/presentation/Screens/charts/widgets/chart_widget.dart b/lib/presentation/Screens/charts/widgets/chart_widget.dart index 5204940f..0f4382a7 100644 --- a/lib/presentation/Screens/charts/widgets/chart_widget.dart +++ b/lib/presentation/Screens/charts/widgets/chart_widget.dart @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:uae_stat/domain/use_cases/language.dart'; // import 'package:syncfusion_flutter_charts/charts.dart'; +import 'package:d_chart/d_chart.dart'; class ChartWidget extends StatelessWidget { ChartWidget({ @@ -44,7 +45,7 @@ class ChartWidget extends StatelessWidget { Color(0xFF578D9C), Color(0xFF7DAFBC), Color(0xFF86C7D9), - Color(0xFF989898), + // Color(0xFF989898), ], }; @@ -1610,8 +1611,14 @@ class ChartWidget extends StatelessWidget { xAxisData.length * (40 + 10); // Compute chart width double screenWidth = constraints.maxWidth; + print('length'); + print(xAxisData.length); + return SingleChildScrollView( scrollDirection: Axis.horizontal, + physics: xAxisData.length < 7 + ? const NeverScrollableScrollPhysics() // Disable scrolling + : const AlwaysScrollableScrollPhysics(), // Enable scrolling padding: const EdgeInsets.only(top: 10, left: 5), child: ConstrainedBox( constraints: BoxConstraints( @@ -2584,7 +2591,9 @@ class ChartWidget extends StatelessWidget { 6, // Softer roundness for tooltips fitInsideHorizontally: true, fitInsideVertically: true, - tooltipPadding: const EdgeInsets.all(5), + // tooltipPadding: const EdgeInsets.all(5), + tooltipPadding: const EdgeInsets.only( + top: 8, bottom: 5, left: 5, right: 5), tooltipMargin: 20, // Reduce margin for better alignment @@ -2608,7 +2617,6 @@ class ChartWidget extends StatelessWidget { ), ); } - // Format values dynamically // String formattedValue = value >= 1e6 // ? '${(value / 1e6).toStringAsFixed(1)}M' @@ -2662,8 +2670,12 @@ class ChartWidget extends StatelessWidget { bottomTitles: AxisTitles( sideTitles: SideTitles( showTitles: true, - reservedSize: - 150, // Added space for rotated titles + reservedSize: (chartData['chart_label_width'] == + null || + chartData['chart_label_width'] == 0) + ? 150 + : chartData[ + 'chart_label_width'], // Added space for rotated titles getTitlesWidget: (value, meta) { if (value < groupByValues.length) { String title = groupByValues.elementAt( @@ -2677,7 +2689,14 @@ class ChartWidget extends StatelessWidget { width: 120, child: Text( title, - textAlign: TextAlign.right, + textAlign: (chartData[ + 'chart_label_width'] == + null || + chartData[ + 'chart_label_width'] == + 0) + ? TextAlign.right + : TextAlign.center, style: const TextStyle(fontSize: 12), softWrap: true, maxLines: 2, @@ -2750,7 +2769,48 @@ class ChartWidget extends StatelessWidget { _buildChartLegend(groupedCrops, parsedChartBarColors, uniqueColors), ], ); - + // case 'd_chart_grouped_bar_horizantal': + // return DChartBar( + // vertical: false, // <--- Important: rotate the chart + // barGroupingType: BarGroupingType.grouped, + // data: const [ + // { + // 'id': 'Product A', + // 'data': [ + // {'domain': 'Jan', 'measure': 30}, + // {'domain': 'Feb', 'measure': 50}, + // {'domain': 'Mar', 'measure': 40}, + // ], + // }, + // { + // 'id': 'Product B', + // 'data': [ + // {'domain': 'Jan', 'measure': 20}, + // {'domain': 'Feb', 'measure': 20}, + // {'domain': 'Mar', 'measure': 35}, + // ], + // }, + // { + // 'id': 'Product C', + // 'data': [ + // {'domain': 'Jan', 'measure': 0}, + // {'domain': 'Feb', 'measure': 25}, + // {'domain': 'Mar', 'measure': 45}, + // ], + // }, + // ], + // groupList: const [ + // {'id': 'Product A', 'color': Colors.orange}, + // {'id': 'Product B', 'color': Colors.deepOrange}, + // {'id': 'Product C', 'color': Colors.pinkAccent}, + // ], + // barValue: (barData, index) => '${barData['measure']}', + // barLabelPosition: BarLabelPosition.outside, + // domainLabelPaddingToAxisLine: 16, + // measureLabelPaddingToAxisLine: 16, + // groupSeparatorWidth: 14, + // barLabelFontSize: 12, + // ); default: return Center(child: Text('Unknown chart type')); } @@ -3073,6 +3133,7 @@ class ChartWidget extends StatelessWidget { style: const TextStyle(color: Colors.white), ), ], + textAlign: TextAlign.left, ); }).toList(); }, diff --git a/pubspec.lock b/pubspec.lock index c92aaef9..bd37164e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -233,6 +233,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.19.1" + community_charts_common: + dependency: transitive + description: + name: community_charts_common + sha256: d997ade57f15490346de46efbe23805d378a672aafbf5e47e19517964b671009 + url: "https://pub.dev" + source: hosted + version: "1.0.4" + community_charts_flutter: + dependency: transitive + description: + name: community_charts_flutter + sha256: "4614846b99782ab79b613687704865e5468ecada3f0ad1afe1cdc3ff5b727f72" + url: "https://pub.dev" + source: hosted + version: "1.0.4" connectivity_plus: dependency: "direct main" description: @@ -329,6 +345,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0+7.3.0" + d_chart: + dependency: "direct main" + description: + name: d_chart + sha256: "231d2c0c65b85a5e557c8293506649bbda1fcbb7292b019cf0a64a6986ccfe1f" + url: "https://pub.dev" + source: hosted + version: "2.10.5" dart_style: dependency: transitive description: @@ -1463,22 +1487,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.1" - syncfusion_flutter_charts: - dependency: "direct main" - description: - name: syncfusion_flutter_charts - sha256: c53e8616368c1a88397b7b180d0ded7d9e960564cdba01509cc5fa2d503ed727 - url: "https://pub.dev" - source: hosted - version: "28.2.9" - syncfusion_flutter_core: - dependency: transitive - description: - name: syncfusion_flutter_core - sha256: "5a1a76eef118e511443b299925d4a802eb8259388d6a580e0ad6413d1a70f987" - url: "https://pub.dev" - source: hosted - version: "28.2.9" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 914510fe..e19f62e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: uae_stat description: "View statistics about the UAE from the Federal Center for Statistics and Competitiveness." publish_to: "none" -version: 1.0.43+44 +version: 1.0.46+47 environment: sdk: ">=3.2.3 <4.0.0" @@ -61,7 +61,6 @@ dependencies: image_picker: ^1.1.2 material_charts: ^0.0.23 flutter_staggered_grid_view: ^0.7.0 - syncfusion_flutter_charts: ^28.1.39 connectivity_plus: ^6.1.2 tutorial_coach_mark: ^1.2.12 package_info_plus: ^8.2.0 @@ -69,6 +68,7 @@ dependencies: boxy: ^2.2.1 firebase_messaging: ^15.2.4 internet_connection_checker: ^3.0.1 + d_chart: ^2.10.5 dependency_overrides: fading_edge_scrollview: ^4.1.1