Skip to main content

b5

alt

import 'package:d_chart/d_chart.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
TimeData maxTimeData = TimeData(domain: DateTime(2024, 1), measure: 10);

List<TimeData> series1 = [
TimeData(domain: DateTime(2024, 1), measure: 10),
TimeData(domain: DateTime(2024, 2), measure: 20),
TimeData(domain: DateTime(2024, 3), measure: 30),
TimeData(domain: DateTime(2024, 4), measure: 50),
TimeData(domain: DateTime(2024, 5), measure: 75),
TimeData(domain: DateTime(2024, 6), measure: 55),
TimeData(domain: DateTime(2024, 7), measure: 65),
TimeData(domain: DateTime(2024, 8), measure: 58),
TimeData(domain: DateTime(2024, 9), measure: 50),
TimeData(domain: DateTime(2024, 10), measure: 88),
TimeData(domain: DateTime(2024, 11), measure: 40),
TimeData(domain: DateTime(2024, 12), measure: 48),
];
void findMaxDomain() {
for (final data in series1) {
if (data.measure > maxTimeData.measure) {
maxTimeData = data;
}
}
setState(() {});
}

void initState() {
findMaxDomain();
super.initState();
}
AspectRatio(
aspectRatio: 16 / 9,
child: DChartBarO(
layoutMargin: LayoutMargin(40, 10, 10, 10),
configRenderBar: ConfigRenderBar(
showBarLabel: true,
barLabelDecorator: BarLabelDecorator(
barLabelPosition: BarLabelPosition.outside,
outsideLabelStyle: const LabelStyle(
fontSize: 8,
color: Colors.black54,
),
),
barGroupInnerPaddingPx: 8,
radius: 2,
maxBarWidthPx: 10,
),
domainAxis: DomainAxis(
showLine: true,
lineStyle: LineStyle(color: Colors.grey.shade200),
tickLength: 0,
gapAxisToLabel: 12,
labelStyle: const LabelStyle(
fontSize: 10,
color: Colors.black54,
),
),
measureAxis: MeasureAxis(
gapAxisToLabel: 8,
numericTickProvider: const NumericTickProvider(
desiredMinTickCount: 5,
desiredMaxTickCount: 10,
),
useGridLine: true,
gridLineStyle: LineStyle(
color: Colors.grey.shade300,
dashPattern: [4],
),
labelStyle: const LabelStyle(
fontSize: 10,
color: Colors.black54,
),
),
barLabelValue: (group, data, index) {
return '${data.measure}';
},
groupList: [
OrdinalGroup(
id: '1',
data: series1,
color: Colors.lightBlue,
),
OrdinalGroup(
id: '2',
data: series2,
color: Colors.deepPurple,
),
],
),
),