Skip to content

Commit

Permalink
custom yAxis name for AreaLineChart
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiHarashchak committed May 29, 2022
1 parent 49bc505 commit a2d8c76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class _MyHomePageState extends State<MyHomePage> with FakeChartSeries {
} else {
chart = AreaLineChart.fromDateTimeMaps(
[line1], [Colors.red.shade900], ['C'],
yAxisName: "Temperature",
gradients: [Pair(Colors.yellow.shade400, Colors.red.shade700)]);
}
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
Expand Down
13 changes: 8 additions & 5 deletions lib/chart/area_line_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ import 'package:flutter/rendering.dart';
class AreaLineChart extends LineChart {
Map<int, Path> _areaPathMap = Map();
final FontWeight? tapTextFontWeight;

final String? yAxisName;
final List<Pair<Color, Color>>? _gradients;

AreaLineChart(List<ChartLine> lines, Dates fromTo, this._gradients,
{this.tapTextFontWeight})
: super(lines, fromTo, tapTextFontWeight: tapTextFontWeight);
{this.tapTextFontWeight, this.yAxisName})
: super(lines, fromTo,
tapTextFontWeight: tapTextFontWeight, yAxisName: yAxisName);

factory AreaLineChart.fromDateTimeMaps(List<Map<DateTime, double>> series,
List<Color> colors, List<String> units,
{List<Pair<Color, Color>>? gradients, FontWeight? tapTextFontWeight}) {
{List<Pair<Color, Color>>? gradients,
FontWeight? tapTextFontWeight,
String? yAxisName}) {
assert(series.length == colors.length);
assert(series.length == units.length);

Pair<List<ChartLine>, Dates> convertFromDateMaps =
DateTimeSeriesConverter.convertFromDateMaps(series, colors, units);
return AreaLineChart(
convertFromDateMaps.left, convertFromDateMaps.right, gradients,
tapTextFontWeight: tapTextFontWeight);
tapTextFontWeight: tapTextFontWeight, yAxisName: yAxisName);
}

List<Pair<Color, Color>>? get gradients => _gradients;
Expand Down

0 comments on commit a2d8c76

Please sign in to comment.