Showing
4 changed files
with
42 additions
and
1 deletions
| @@ -30,9 +30,11 @@ class BarDataSet extends Dataset { | @@ -30,9 +30,11 @@ class BarDataSet extends Dataset { | ||
| 30 | this.surfaceOpacity = 1, | 30 | this.surfaceOpacity = 1, |
| 31 | this.width = 10, | 31 | this.width = 10, |
| 32 | this.offset = 0, | 32 | this.offset = 0, |
| 33 | + this.axis = Axis.horizontal, | ||
| 33 | }) : drawBorder = drawBorder ?? borderColor != null && color != borderColor, | 34 | }) : drawBorder = drawBorder ?? borderColor != null && color != borderColor, |
| 34 | assert((drawBorder ?? borderColor != null && color != borderColor) || | 35 | assert((drawBorder ?? borderColor != null && color != borderColor) || |
| 35 | drawSurface), | 36 | drawSurface), |
| 37 | + assert(axis != null), | ||
| 36 | super( | 38 | super( |
| 37 | legend: legend, | 39 | legend: legend, |
| 38 | color: color, | 40 | color: color, |
| @@ -51,11 +53,27 @@ class BarDataSet extends Dataset { | @@ -51,11 +53,27 @@ class BarDataSet extends Dataset { | ||
| 51 | final double width; | 53 | final double width; |
| 52 | final double offset; | 54 | final double offset; |
| 53 | 55 | ||
| 56 | + final Axis axis; | ||
| 57 | + | ||
| 54 | void _drawSurface(Context context, ChartGrid grid, LineChartValue value) { | 58 | void _drawSurface(Context context, ChartGrid grid, LineChartValue value) { |
| 59 | + switch (axis) { | ||
| 60 | + case Axis.horizontal: | ||
| 55 | final double y = (grid is CartesianGrid) ? grid.xAxisOffset : 0; | 61 | final double y = (grid is CartesianGrid) ? grid.xAxisOffset : 0; |
| 56 | final PdfPoint p = grid.toChart(value.point); | 62 | final PdfPoint p = grid.toChart(value.point); |
| 63 | + final double x = p.x + offset - width / 2; | ||
| 64 | + final double height = p.y - y; | ||
| 65 | + | ||
| 66 | + context.canvas.drawRect(x, y, width, height); | ||
| 67 | + break; | ||
| 68 | + case Axis.vertical: | ||
| 69 | + final double x = (grid is CartesianGrid) ? grid.yAxisOffset : 0; | ||
| 70 | + final PdfPoint p = grid.toChart(value.point); | ||
| 71 | + final double y = p.y + offset - width / 2; | ||
| 72 | + final double height = p.x - x; | ||
| 57 | 73 | ||
| 58 | - context.canvas.drawRect(p.x + offset - width / 2, y, width, p.y - y); | 74 | + context.canvas.drawRect(x, y, height, width); |
| 75 | + break; | ||
| 76 | + } | ||
| 59 | } | 77 | } |
| 60 | 78 | ||
| 61 | @override | 79 | @override |
| @@ -191,6 +191,28 @@ void main() { | @@ -191,6 +191,28 @@ void main() { | ||
| 191 | ), | 191 | ), |
| 192 | )); | 192 | )); |
| 193 | }); | 193 | }); |
| 194 | + | ||
| 195 | + test('Vertical BarChart', () { | ||
| 196 | + pdf.addPage(Page( | ||
| 197 | + pageFormat: PdfPageFormat.standard.landscape, | ||
| 198 | + build: (Context context) => Chart( | ||
| 199 | + grid: CartesianGrid( | ||
| 200 | + xAxis: FixedAxis<int>(<int>[0, 1, 2, 3, 4, 5, 6]), | ||
| 201 | + yAxis: FixedAxis<int>(<int>[0, 3, 6, 9], divisions: true), | ||
| 202 | + ), | ||
| 203 | + datasets: <Dataset>[ | ||
| 204 | + BarDataSet( | ||
| 205 | + axis: Axis.vertical, | ||
| 206 | + data: const <LineChartValue>[ | ||
| 207 | + LineChartValue(1, 1), | ||
| 208 | + LineChartValue(2, 3), | ||
| 209 | + LineChartValue(3, 7), | ||
| 210 | + ], | ||
| 211 | + ), | ||
| 212 | + ], | ||
| 213 | + ), | ||
| 214 | + )); | ||
| 215 | + }); | ||
| 194 | }); | 216 | }); |
| 195 | 217 | ||
| 196 | tearDownAll(() { | 218 | tearDownAll(() { |
No preview for this file type
-
Please register or login to post a comment