|
|
|
|
@ -6,16 +6,16 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import '../../Constants.dart';
|
|
|
|
|
|
|
|
|
|
class ShowChart extends StatelessWidget {
|
|
|
|
|
final String title;
|
|
|
|
|
final List<TimeSeriesSales2> timeSeries;
|
|
|
|
|
final int indexes;
|
|
|
|
|
final String? title;
|
|
|
|
|
final List<TimeSeriesSales2>? timeSeries;
|
|
|
|
|
final int? indexes;
|
|
|
|
|
final double horizontalInterval;
|
|
|
|
|
final bool isWeeklyOrMonthly;
|
|
|
|
|
|
|
|
|
|
ShowChart({this.title, this.timeSeries, this.indexes, this.horizontalInterval = 8.0, this.isWeeklyOrMonthly = false});
|
|
|
|
|
|
|
|
|
|
List<int> xAxixs = List();
|
|
|
|
|
List<double> yAxixs = List();
|
|
|
|
|
List<int> xAxixs = [];
|
|
|
|
|
List<double> yAxixs = [];
|
|
|
|
|
|
|
|
|
|
double minY = 0;
|
|
|
|
|
double maxY = 0;
|
|
|
|
|
@ -50,7 +50,7 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
title,
|
|
|
|
|
title!,
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 16, letterSpacing: -0.64, fontWeight: FontWeight.w600),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
@ -79,19 +79,19 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getXaxix() {
|
|
|
|
|
for (int index = 0; index < timeSeries.length; index++) {
|
|
|
|
|
int mIndex = indexes * index;
|
|
|
|
|
if (mIndex < timeSeries.length) {
|
|
|
|
|
for (int index = 0; index < timeSeries!.length; index++) {
|
|
|
|
|
int mIndex = indexes! * index!;
|
|
|
|
|
if (mIndex < timeSeries!.length) {
|
|
|
|
|
xAxixs.add(mIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getYaxix() {
|
|
|
|
|
for (int index = 0; index < timeSeries.length; index++) {
|
|
|
|
|
int mIndex = indexes * index;
|
|
|
|
|
if (mIndex < timeSeries.length) {
|
|
|
|
|
yAxixs.add(timeSeries[mIndex].sales);
|
|
|
|
|
for (int index = 0; index < timeSeries!.length; index++) {
|
|
|
|
|
int mIndex = indexes! * index!;
|
|
|
|
|
if (mIndex < timeSeries!.length) {
|
|
|
|
|
yAxixs.add(timeSeries![mIndex].sales);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -102,7 +102,7 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
touchTooltipData: LineTouchTooltipData(
|
|
|
|
|
tooltipBgColor: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
touchCallback: (touchEvent, LineTouchResponse touchResponse) {},
|
|
|
|
|
touchCallback: (touchEvent, LineTouchResponse? touchResponse) {},
|
|
|
|
|
handleBuiltInTouches: true,
|
|
|
|
|
),
|
|
|
|
|
gridData: FlGridData(show: true, drawVerticalLine: true, drawHorizontalLine: true),
|
|
|
|
|
@ -117,18 +117,18 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
margin: 22,
|
|
|
|
|
getTitles: (value) {
|
|
|
|
|
if (isWeeklyOrMonthly) {
|
|
|
|
|
return '${timeSeries[value.toInt()].time.day}/ ${timeSeries[value.toInt()].time.month}';
|
|
|
|
|
return '${timeSeries![value.toInt()].time.day}/ ${timeSeries![value.toInt()].time.month}';
|
|
|
|
|
} else {
|
|
|
|
|
if (timeSeries.length < 15) {
|
|
|
|
|
if (timeSeries.length > value.toInt()) {
|
|
|
|
|
return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
if (timeSeries!.length < 15) {
|
|
|
|
|
if (timeSeries!.length > value.toInt()) {
|
|
|
|
|
return '${timeSeries![value.toInt()].time.month}/ ${timeSeries![value.toInt()].time.year}';
|
|
|
|
|
} else
|
|
|
|
|
return '';
|
|
|
|
|
} else {
|
|
|
|
|
if (value.toInt() == 0) return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
if (value.toInt() == timeSeries.length - 1) return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
if (value.toInt() == 0) return '${timeSeries![value.toInt()].time.month}/ ${timeSeries![value.toInt()].time.year}';
|
|
|
|
|
if (value.toInt() == timeSeries!.length - 1) return '${timeSeries![value.toInt()].time.month}/ ${timeSeries![value.toInt()].time.year}';
|
|
|
|
|
if (xAxixs.contains(value.toInt())) {
|
|
|
|
|
return '${timeSeries[value.toInt()].time.month}/ ${timeSeries[value.toInt()].time.year}';
|
|
|
|
|
return '${timeSeries![value.toInt()].time.month}/ ${timeSeries![value.toInt()].time.year}';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
@ -184,7 +184,7 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
getMin();
|
|
|
|
|
getMinY();
|
|
|
|
|
try {
|
|
|
|
|
increasingY = ((maxY - minY) / timeSeries.length - 1) * 15;
|
|
|
|
|
increasingY = ((maxY - minY) / timeSeries!.length - 1) * 15;
|
|
|
|
|
maxY += increasingY.abs();
|
|
|
|
|
minY -= increasingY.abs();
|
|
|
|
|
} catch(ex) {
|
|
|
|
|
@ -199,7 +199,7 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
|
|
|
|
|
double getMaxY() {
|
|
|
|
|
maxY = 0;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
timeSeries!.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble > maxY) {
|
|
|
|
|
lastY = resultValueDouble;
|
|
|
|
|
@ -212,8 +212,8 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
|
|
|
|
|
double getInitialY() {
|
|
|
|
|
try {
|
|
|
|
|
intialY = timeSeries.first.sales;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
intialY = timeSeries!.first.sales;
|
|
|
|
|
timeSeries!.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble < intialY) intialY = resultValueDouble;
|
|
|
|
|
});
|
|
|
|
|
@ -226,12 +226,12 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getMaxX() {
|
|
|
|
|
maxX = (timeSeries.length - 1).toDouble();
|
|
|
|
|
maxX = (timeSeries!.length - 1).toDouble();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getMin() {
|
|
|
|
|
minX = 0;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
timeSeries!.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble < minX) minX = resultValueDouble;
|
|
|
|
|
});
|
|
|
|
|
@ -241,7 +241,7 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
|
|
|
|
|
double getMinY() {
|
|
|
|
|
minY = 0;
|
|
|
|
|
timeSeries.forEach((element) {
|
|
|
|
|
timeSeries!.forEach((element) {
|
|
|
|
|
double resultValueDouble = element.sales;
|
|
|
|
|
if (resultValueDouble < minY) minY = resultValueDouble;
|
|
|
|
|
});
|
|
|
|
|
@ -251,15 +251,15 @@ class ShowChart extends StatelessWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<LineChartBarData> getData(context) {
|
|
|
|
|
List<FlSpot> spots = List();
|
|
|
|
|
for (int index = 0; index < timeSeries.length; index++) {
|
|
|
|
|
spots.add(FlSpot(index.toDouble(), timeSeries[index].sales));
|
|
|
|
|
List<FlSpot> spots =[];
|
|
|
|
|
for (int index = 0; index < timeSeries!.length; index++) {
|
|
|
|
|
spots.add(FlSpot(index.toDouble(), timeSeries![index].sales));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final LineChartBarData lineChartBarData1 = LineChartBarData(
|
|
|
|
|
spots: spots,
|
|
|
|
|
isCurved: true,
|
|
|
|
|
colors: [secondaryColor],
|
|
|
|
|
colors: [secondaryColor!],
|
|
|
|
|
barWidth: 1.5,
|
|
|
|
|
isStrokeCapRound: true,
|
|
|
|
|
dotData: FlDotData(
|
|
|
|
|
|