From c657b10c5a35c40106c12c81dd677528ad6e1ee3 Mon Sep 17 00:00:00 2001 From: wutsi Date: Sun, 25 Dec 2022 11:50:13 -0500 Subject: [PATCH] update chart --- CHANGELOG.md | 2 +- lib/src/chart.dart | 43 ++++++++++++++++++++++++++++++++++--------- pubspec.yaml | 4 ++-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a95a8c..77bf4bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## [0.1.184] 2022-12-24 +## [0.1.190] 2022-12-24 - ADD: Add chart component diff --git a/lib/src/chart.dart b/lib/src/chart.dart index 2219be9..a9b8b1a 100644 --- a/lib/src/chart.dart +++ b/lib/src/chart.dart @@ -1,4 +1,5 @@ import 'package:flutter/cupertino.dart'; +import 'package:sdui/src/logger.dart'; import 'package:sdui/src/widget.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; @@ -6,6 +7,7 @@ import 'package:syncfusion_flutter_charts/charts.dart'; /// This class does nothing. It's up the the application using this library /// to provide it's own implementation and set the global variable [sduiAnalytics]. class SDUIChart extends SDUIWidget { + final _logger = LoggerFactory.create("SDUIChart"); String? _title; final List> _series = []; @@ -14,14 +16,25 @@ class SDUIChart extends SDUIWidget { _title = json?["title"]; var series = json?["series"]; + if (series is List) { - List list = []; for (var element in series) { - if (element is Map) { - list.add(ChartData.fromJson(element)); + if (element is List) { + List serie = []; + + for (var data in element) { + if (data is Map) { + _logger.i('Adding data: $data'); + serie.add(ChartData.fromJson(data)); + } else { + _logger.i('Not data: $data'); + } + } + + _logger.i('serie= $serie'); + _series.add(serie); } } - _series.add(list); } return super.fromJson(json); } @@ -31,11 +44,20 @@ class SDUIChart extends SDUIWidget { return SfCartesianChart( title: _title == null ? null : ChartTitle(text: _title!), primaryXAxis: CategoryAxis(), - series: _series.map((e) => LineSeries( - dataSource: e, - xValueMapper: (ChartData data, _) => data.x, - yValueMapper: (ChartData data, _) => data.y, - ))); + series: _toSeries()); + } + + List _toSeries() { + var result = []; + for (var element in _series) { + result.add(LineSeries( + dataSource: element, + xValueMapper: (ChartData data, _) => data.x, + yValueMapper: (ChartData data, _) => data.y, + )); + } + + return result; } } @@ -50,4 +72,7 @@ class ChartData { return data; } + + @override + String toString() => "ChartData($x = $y)"; } diff --git a/pubspec.yaml b/pubspec.yaml index e7f6859..c314c8f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,12 +16,12 @@ description: SDUI make it easy to implement Server Driven UI pattern on flutter. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.1.184 +version: 0.1.190 environment: sdk: ">=2.12.0 <3.0.0" -# Dependencies specify other packages that your package needs in order to work. +# Dependencies specify othe9r packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions # consider running `flutter pub upgrade --major-versions`. Alternatively, # dependencies can be manually updated by changing the version numbers below to