|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:syncfusion_flutter_charts/charts.dart'; |
| 3 | + |
| 4 | +import '../model.dart'; |
| 5 | + |
| 6 | +class ColorAndBorderSample extends StatefulWidget { |
| 7 | + const ColorAndBorderSample({super.key}); |
| 8 | + |
| 9 | + @override |
| 10 | + State<ColorAndBorderSample> createState() => _ColorAndBorderSampleState(); |
| 11 | +} |
| 12 | + |
| 13 | +class _ColorAndBorderSampleState extends State<ColorAndBorderSample> { |
| 14 | + @override |
| 15 | + Widget build(BuildContext context) { |
| 16 | + return Scaffold( |
| 17 | + body: GridView.count( |
| 18 | + crossAxisCount: 3, |
| 19 | + childAspectRatio: 1.6, |
| 20 | + mainAxisSpacing: 25, |
| 21 | + children: [ |
| 22 | + SfCartesianChart( |
| 23 | + primaryXAxis: const CategoryAxis( |
| 24 | + labelPlacement: LabelPlacement.onTicks, |
| 25 | + axisLine: AxisLine(width: 0), |
| 26 | + ), |
| 27 | + primaryYAxis: const NumericAxis( |
| 28 | + axisLine: AxisLine(width: 0), |
| 29 | + maximum: 120, |
| 30 | + interval: 20, |
| 31 | + ), |
| 32 | + series: <CartesianSeries<ChartData, String>>[ |
| 33 | + SplineSeries( |
| 34 | + dataSource: categoryMidData1, |
| 35 | + xValueMapper: (ChartData data, int index) => data.x, |
| 36 | + yValueMapper: (ChartData data, int index) => data.y, |
| 37 | + color: Colors.green, |
| 38 | + width: 2, |
| 39 | + markerSettings: const MarkerSettings(isVisible: true), |
| 40 | + ), |
| 41 | + ], |
| 42 | + ), |
| 43 | + SfCartesianChart( |
| 44 | + plotAreaBorderWidth: 0, |
| 45 | + primaryXAxis: const CategoryAxis( |
| 46 | + axisLine: AxisLine(width: 0), |
| 47 | + ), |
| 48 | + primaryYAxis: const NumericAxis( |
| 49 | + axisLine: AxisLine(width: 0), |
| 50 | + maximum: 120, |
| 51 | + interval: 20, |
| 52 | + ), |
| 53 | + series: <CartesianSeries<ChartData, String>>[ |
| 54 | + BarSeries( |
| 55 | + dataSource: categoryMidData2, |
| 56 | + xValueMapper: (ChartData data, int index) => data.x, |
| 57 | + yValueMapper: (ChartData data, int index) => data.y, |
| 58 | + color: Colors.indigo.withOpacity(0.2), |
| 59 | + borderColor: Colors.indigo, |
| 60 | + borderWidth: 2, |
| 61 | + ), |
| 62 | + ], |
| 63 | + ), |
| 64 | + SfCartesianChart( |
| 65 | + plotAreaBorderWidth: 0, |
| 66 | + primaryXAxis: const CategoryAxis( |
| 67 | + plotOffset: 5, |
| 68 | + labelPlacement: LabelPlacement.onTicks, |
| 69 | + axisLine: AxisLine(width: 0), |
| 70 | + ), |
| 71 | + primaryYAxis: const NumericAxis( |
| 72 | + axisLine: AxisLine(width: 0), |
| 73 | + ), |
| 74 | + series: <CartesianSeries<ChartData, String>>[ |
| 75 | + ScatterSeries( |
| 76 | + dataSource: categoryMidData1, |
| 77 | + xValueMapper: (ChartData data, int index) => data.x, |
| 78 | + yValueMapper: (ChartData data, int index) => data.y, |
| 79 | + color: Colors.teal.withOpacity(0.2), |
| 80 | + borderColor: Colors.teal, |
| 81 | + borderWidth: 2, |
| 82 | + ), |
| 83 | + ], |
| 84 | + ), |
| 85 | + SfCartesianChart( |
| 86 | + primaryXAxis: const CategoryAxis( |
| 87 | + labelPlacement: LabelPlacement.onTicks, |
| 88 | + axisLine: AxisLine(width: 0), |
| 89 | + ), |
| 90 | + primaryYAxis: const NumericAxis( |
| 91 | + axisLine: AxisLine(width: 0), |
| 92 | + ), |
| 93 | + series: <CartesianSeries<ChartData, String>>[ |
| 94 | + AreaSeries( |
| 95 | + dataSource: categoryMidData1, |
| 96 | + xValueMapper: (ChartData data, int index) => data.x, |
| 97 | + yValueMapper: (ChartData data, int index) => data.y, |
| 98 | + color: Colors.pink.withOpacity(0.2), |
| 99 | + borderColor: Colors.pink, |
| 100 | + borderWidth: 2, |
| 101 | + borderDrawMode: BorderDrawMode.top, |
| 102 | + ), |
| 103 | + ], |
| 104 | + annotations: [ |
| 105 | + CartesianChartAnnotation( |
| 106 | + x: 'Jul', |
| 107 | + y: 113, |
| 108 | + widget: ColoredBox( |
| 109 | + color: Theme.of(context).colorScheme.surface, |
| 110 | + child: const Text( |
| 111 | + 'Border Draw Mode: Top', |
| 112 | + style: TextStyle( |
| 113 | + fontWeight: FontWeight.w600, |
| 114 | + ), |
| 115 | + ), |
| 116 | + ), |
| 117 | + coordinateUnit: CoordinateUnit.point, |
| 118 | + ), |
| 119 | + ], |
| 120 | + ), |
| 121 | + SfCartesianChart( |
| 122 | + plotAreaBorderWidth: 0, |
| 123 | + primaryXAxis: const CategoryAxis( |
| 124 | + plotOffset: 1.5, |
| 125 | + labelPlacement: LabelPlacement.onTicks, |
| 126 | + axisLine: AxisLine(width: 0), |
| 127 | + ), |
| 128 | + primaryYAxis: const NumericAxis( |
| 129 | + axisLine: AxisLine(width: 0), |
| 130 | + ), |
| 131 | + series: <CartesianSeries<ChartData, String>>[ |
| 132 | + SplineAreaSeries( |
| 133 | + dataSource: categoryMidData1, |
| 134 | + xValueMapper: (ChartData data, int index) => data.x, |
| 135 | + yValueMapper: (ChartData data, int index) => data.y, |
| 136 | + color: Colors.purple.withOpacity(0.2), |
| 137 | + borderColor: Colors.purple, |
| 138 | + borderWidth: 2, |
| 139 | + borderDrawMode: BorderDrawMode.excludeBottom, |
| 140 | + ), |
| 141 | + ], |
| 142 | + annotations: [ |
| 143 | + CartesianChartAnnotation( |
| 144 | + x: 'Jul', |
| 145 | + y: 113, |
| 146 | + widget: ColoredBox( |
| 147 | + color: Theme.of(context).colorScheme.surface, |
| 148 | + child: const Text( |
| 149 | + 'Border Draw Mode: excludeBottom', |
| 150 | + style: TextStyle( |
| 151 | + fontWeight: FontWeight.w600, |
| 152 | + ), |
| 153 | + ), |
| 154 | + ), |
| 155 | + coordinateUnit: CoordinateUnit.point, |
| 156 | + ), |
| 157 | + ], |
| 158 | + ), |
| 159 | + SfCartesianChart( |
| 160 | + plotAreaBorderWidth: 0, |
| 161 | + primaryXAxis: const CategoryAxis( |
| 162 | + plotOffset: 1.5, |
| 163 | + labelPlacement: LabelPlacement.onTicks, |
| 164 | + axisLine: AxisLine(width: 0), |
| 165 | + ), |
| 166 | + primaryYAxis: const NumericAxis( |
| 167 | + plotOffset: 1.5, |
| 168 | + axisLine: AxisLine(width: 0), |
| 169 | + maximum: 120, |
| 170 | + interval: 20, |
| 171 | + ), |
| 172 | + series: <CartesianSeries<ChartData, String>>[ |
| 173 | + StepAreaSeries( |
| 174 | + dataSource: categoryMidData2, |
| 175 | + xValueMapper: (ChartData data, int index) => data.x, |
| 176 | + yValueMapper: (ChartData data, int index) => data.y, |
| 177 | + color: Colors.blue.withOpacity(0.2), |
| 178 | + borderColor: Colors.blue, |
| 179 | + borderWidth: 2, |
| 180 | + borderDrawMode: BorderDrawMode.all, |
| 181 | + ), |
| 182 | + ], |
| 183 | + annotations: [ |
| 184 | + CartesianChartAnnotation( |
| 185 | + x: 'Jul', |
| 186 | + y: 113, |
| 187 | + widget: ColoredBox( |
| 188 | + color: Theme.of(context).colorScheme.surface, |
| 189 | + child: const Text( |
| 190 | + 'Border Draw Mode: all', |
| 191 | + style: TextStyle( |
| 192 | + fontWeight: FontWeight.w600, |
| 193 | + ), |
| 194 | + ), |
| 195 | + ), |
| 196 | + coordinateUnit: CoordinateUnit.point, |
| 197 | + ), |
| 198 | + ], |
| 199 | + ), |
| 200 | + ], |
| 201 | + ), |
| 202 | + ); |
| 203 | + } |
| 204 | +} |
0 commit comments