Merge branch 'fix_theme_issues' into 'development'

fix the line chart issues

See merge request Cloud_Solution/diplomatic-quarter!289
merge-requests/290/merge
Mohammad Aljammal 5 years ago
commit a613fe08e4

@ -14,10 +14,18 @@ class LineChartCurved extends StatelessWidget {
List<int> xAxixs = List(); List<int> xAxixs = List();
List<double> yAxixs = List(); List<double> yAxixs = List();
double minY = 0;
double maxY = 0;
double minX = 0;
double maxX = 0;
double increasingY = 0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
getXaxix(); getXaxix();
getYaxix(); getYaxix();
calculateMaxAndMin();
return AspectRatio( return AspectRatio(
aspectRatio: 1.1, aspectRatio: 1.1,
child: Container( child: Container(
@ -70,10 +78,18 @@ class LineChartCurved extends StatelessWidget {
} }
} }
} }
getYaxix() { getYaxix() {
int indexess= (timeSeries.length*0.30).toInt(); // int indexess= (timeSeries.length*0.30).toInt();
// for (int index = 0; index < timeSeries.length; index++) {
// int mIndex = indexess * index;
// if (mIndex < timeSeries.length) {
// yAxixs.add(timeSeries[mIndex].sales);
// }
// }
for (int index = 0; index < timeSeries.length; index++) { for (int index = 0; index < timeSeries.length; index++) {
int mIndex = indexess * index; int mIndex = indexes * index;
if (mIndex < timeSeries.length) { if (mIndex < timeSeries.length) {
yAxixs.add(timeSeries[mIndex].sales); yAxixs.add(timeSeries[mIndex].sales);
} }
@ -100,7 +116,6 @@ class LineChartCurved extends StatelessWidget {
fontSize: 10, fontSize: 10,
), ),
rotateAngle:-65, rotateAngle:-65,
//rotateAngle:-65,
margin: 22, margin: 22,
getTitles: (value) { getTitles: (value) {
if (timeSeries.length < 15) { if (timeSeries.length < 15) {
@ -128,18 +143,18 @@ class LineChartCurved extends StatelessWidget {
fontSize: 10, fontSize: 10,
), ),
getTitles: (value) { getTitles: (value) {
// if (timeSeries.length < 10) { if (timeSeries.length < 15) {
// return '${value.toInt()}'; return '${value.toInt()}';
// } else { } else {
// if (value == getMinY()) if (value == minY)
// return '${value.toInt()}'; return '${value.toInt()}';
// if (value == getMaxY()) if (value == getMaxY())
// return '${value.toInt()}'; return '${value.toInt()}';
// if (yAxixs.contains(value)) { //if (yAxixs.contains(value)) {
// return '${value.toInt()}'; return '${value.toInt()}';
// }
// return ''; return '';
// } }
return '${value.toInt()}'; return '${value.toInt()}';
}, },
margin: 12, margin: 12,
@ -163,31 +178,55 @@ class LineChartCurved extends StatelessWidget {
), ),
), ),
), ),
minX: 0, minX: minX,
maxX: (timeSeries.length - 1).toDouble(), maxX: maxX,
maxY: getMaxY()+0.3, maxY: maxY,
minY: getMinY(), minY: minY,
lineBarsData: getData(context), lineBarsData: getData(context),
); );
} }
calculateMaxAndMin(){
getMaxY();
getMaxX();
getMin();
getMinY();
increasingY = ((maxY-minY)/timeSeries.length - 1)*15;
maxY += increasingY.abs();
minY -= increasingY.abs();
}
double getMaxY() { double getMaxY() {
double max = 0; maxY = 0;
timeSeries.forEach((element) {
double resultValueDouble = element.sales;
if (resultValueDouble > maxY) maxY = resultValueDouble;
});
return maxY.roundToDouble() ;
}
getMaxX(){
maxX = (timeSeries.length - 1).toDouble();
}
double getMin(){
minX = 0;
timeSeries.forEach((element) { timeSeries.forEach((element) {
double resultValueDouble = element.sales; double resultValueDouble = element.sales;
if (resultValueDouble > max) max = resultValueDouble; if (resultValueDouble < minX) minX = resultValueDouble;
}); });
return max.roundToDouble() ; return minX.roundToDouble() ;
} }
double getMinY() { double getMinY() {
double min = timeSeries[0].sales; minY = 0;
timeSeries.forEach((element) { timeSeries.forEach((element) {
double resultValueDouble = element.sales; double resultValueDouble = element.sales;
if (resultValueDouble < min) min = resultValueDouble; if (resultValueDouble < minY) minY = resultValueDouble;
}); });
int value = min.toInt(); int value = minY.toInt();
return value.toDouble(); return value.toDouble();
} }
@ -202,7 +241,7 @@ class LineChartCurved extends StatelessWidget {
spots: spots, spots: spots,
isCurved: true, isCurved: true,
colors: [secondaryColor], colors: [secondaryColor],
barWidth: 5, barWidth: 3,
isStrokeCapRound: true, isStrokeCapRound: true,
dotData: FlDotData( dotData: FlDotData(
show: false, show: false,

@ -178,8 +178,8 @@ class LineChartCurvedBloodPressure extends StatelessWidget {
), ),
minX: 0, minX: 0,
maxX: (timeSeries1.length - 1).toDouble(), maxX: (timeSeries1.length - 1).toDouble(),
maxY: getMaxY() + 0.3, maxY: getMaxY() + 15,
minY: getMinY(), minY: getMinY()-15,
lineBarsData: getData(context), lineBarsData: getData(context),
); );
} }

Loading…
Cancel
Save