diff --git a/lib/pages/medical/vital_sign/LineChartCurved.dart b/lib/pages/medical/vital_sign/LineChartCurved.dart index f097f44c..55e5581f 100644 --- a/lib/pages/medical/vital_sign/LineChartCurved.dart +++ b/lib/pages/medical/vital_sign/LineChartCurved.dart @@ -17,6 +17,8 @@ class LineChartCurved extends StatelessWidget { double minY = 0; double maxY = 0; + double intialY = 0; + double lastY = 0; double minX = 0; double maxX = 0; @@ -26,6 +28,7 @@ class LineChartCurved extends StatelessWidget { Widget build(BuildContext context) { getXaxix(); getYaxix(); + getInitialY(); calculateMaxAndMin(); return AspectRatio( aspectRatio: 1.0, @@ -100,7 +103,7 @@ class LineChartCurved extends StatelessWidget { touchCallback: (LineTouchResponse touchResponse) {}, handleBuiltInTouches: true, ), - gridData: FlGridData(show: true, drawVerticalLine: true, drawHorizontalLine: true,horizontalInterval: 14,verticalInterval: 14), + gridData: FlGridData(show: true, drawVerticalLine: true, drawHorizontalLine: true, horizontalInterval: 14, verticalInterval: 14), titlesData: FlTitlesData( bottomTitles: SideTitles( showTitles: true, @@ -165,12 +168,14 @@ class LineChartCurved extends StatelessWidget { ), minX: minX, maxX: maxX, - maxY: maxY, - minY: 0, + maxY: lastY+50, + minY: intialY, lineBarsData: getData(context), ); } + + calculateMaxAndMin() { getMaxY(); getMaxX(); @@ -185,12 +190,29 @@ class LineChartCurved extends StatelessWidget { maxY = 0; timeSeries.forEach((element) { double resultValueDouble = element.sales; - if (resultValueDouble > maxY) maxY = resultValueDouble; + if (resultValueDouble > maxY) { + lastY = resultValueDouble; + maxY = resultValueDouble; + } }); - + print("maxY " + lastY.toString()); return maxY.roundToDouble(); } + double getInitialY() { + try { + intialY = timeSeries.first.sales; + timeSeries.forEach((element) { + double resultValueDouble = element.sales; + if (resultValueDouble < intialY) intialY = resultValueDouble; + }); + } catch (e) { + intialY = 0; + } + + return intialY.roundToDouble(); + } + getMaxX() { maxX = (timeSeries.length - 1).toDouble(); }