/// <summary> /// Vykreslení hodnot sloupcového grafu /// </summary> /// <param name="yAsix"></param> private void DrawBarChartValues(CMLChartYAsix yAsix) { if (yAsix != null) { var asixStartPointX = Width - (int)Math.Floor(Width * offsetX); var asixXEndPointX = (int)Math.Floor(Width * offsetX); var asixMaxPointY = (int)Math.Floor(Height * offsetYTop); var asixMinPointY = (int)Math.Floor(Height * offsetYBottom); for (int i = 0; i < yAsix.Values.Length; i++) { var distance = ((double)i / yAsix.Values.Length) * (asixXEndPointX - asixStartPointX); var valuePart = (yAsix.Values[i] - yAsix.MinValue) * (1 / (yAsix.MaxValue - yAsix.MinValue)); var barHeight = (int)((asixMinPointY - asixMaxPointY) * valuePart); var x = (int)(distance + asixStartPointX); var y = (int)Math.Floor(Height * offsetYBottom) - barHeight; var width = (int)(((double)1 / yAsix.Values.Length) * (asixXEndPointX - asixStartPointX)); if (yAsix.Fill) { BarPaint.Style = SKPaintStyle.Fill; } _canvas.DrawRect(new SKRect(x, y, x + width, y + barHeight), BarPaint); } } }
/// <summary> /// Vykreslení hodnot čárového grafu /// </summary> /// <param name="yAsix"></param> private void DrawLineChartValues(CMLChartYAsix yAsix) { if (yAsix != null) { var asixStartPointX = Width - (int)Math.Floor(Width * offsetX); var asixXEndPointX = (int)Math.Floor(Width * offsetX); var asixMaxPointY = (int)Math.Floor(Height * offsetYTop); var asixMinPointY = (int)Math.Floor(Height * offsetYBottom); SKPoint[] bezierPoints = new SKPoint[yAsix.Values.Length + 1]; for (int i = 0; i < yAsix.Values.Length; i++) { var distance = ((double)i / yAsix.Values.Length) * (asixXEndPointX - asixStartPointX); var valuePart = (yAsix.Values[i] - yAsix.MinValue) * (1 / (yAsix.MaxValue - yAsix.MinValue)); var pointHeight = ((asixMinPointY - asixMaxPointY) * valuePart); var x = (float)(distance + asixStartPointX); var y = (float)((Height * offsetYBottom) - pointHeight); bezierPoints[i] = new SKPoint(x, y); } bezierPoints[yAsix.Values.Length] = bezierPoints[yAsix.Values.Length - 1]; SKPath path = new SKPath(); path.MoveTo(bezierPoints[0]); for (int i = 1; i < bezierPoints.Length; i += 3) { path.CubicTo(bezierPoints[i], bezierPoints[i + 1], bezierPoints[i + 2]); } path.MoveTo(bezierPoints[bezierPoints.Length - 1]); LinePaint.Style = SKPaintStyle.Stroke; _canvas.DrawPath(path, LinePaint); } }