Skip to content

Commit

Permalink
add support for more chart
Browse files Browse the repository at this point in the history
  • Loading branch information
wutsi committed Jan 19, 2023
1 parent 17011dd commit c8f972e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## [0.1.198] 2023-01-19

## Changes

- Add support for more chart

## [0.1.197] 2023-01-14

## Changes
Expand Down
54 changes: 47 additions & 7 deletions lib/src/chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import 'package:syncfusion_flutter_charts/charts.dart';
class SDUIChart extends SDUIWidget {
final _logger = LoggerFactory.create("SDUIChart");
String? _title;
String? _type;
final List<List<ChartData>> _series = [];

@override
SDUIWidget fromJson(Map<String, dynamic>? json) {
_title = json?["title"];
_type = json?["type"];

var series = json?["series"];

Expand Down Expand Up @@ -47,14 +49,52 @@ class SDUIChart extends SDUIWidget {
series: _toSeries());
}

List<LineSeries> _toSeries() {
var result = <LineSeries>[];
List<XyDataSeries> _toSeries() {
var result = <XyDataSeries>[];
for (var element in _series) {
result.add(LineSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
));
XyDataSeries<ChartData, String> item;
switch (_type?.toLowerCase()) {
case "line":
item = LineSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
);
break;

case "spline":
item = SplineSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
);
break;

case "bar":
item = BarSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
);
break;

case "step":
item = StepLineSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
);
break;

default:
item = ColumnSeries<ChartData, String>(
dataSource: element,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
);
}

result.add(item);
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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.197
version: 0.1.198

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit c8f972e

Please sign in to comment.