protected void ShowSliderValuesPosition(SKCanvas canvas, SKRect frame) { if (!IsSliderVisible) { return; } var valueItems = ChartEntries.GetChartValueItemFromX(TouchedPoint.X, frame, MaxItems); if (valueItems?.Any() != true) { return; } int index = 0; foreach (var item in valueItems) { canvas.DrawSliderCircle(item.ChartValueItem.Point.X, item.ChartValueItem.Point.Y, item.Color, this.SliderPointSize); string text = Math.Round(double.Parse(item.ChartValueItem.Value.ToString()), 0, MidpointRounding.AwayFromZero).ToString() + " " + this.VerticalUnit; canvas.DrawSliderValue( text, frame.GetInsideXValue(TouchedPoint.X), frame.Top, SliderDetailTextSize, SKColors.White, item.Color, SliderDetailPadding, SliderDetailMargin, MaxValue + " " + this.VerticalUnit, valueItems.Count, index, SliderDetailOrientation, frame, item.Parent?.UseDashedEffect == true); index++; } }
protected void ShowExactSliderValuesPosition(SKCanvas canvas, SKRect frame) { if (!IsSliderVisible) { return; } var valueItems = ChartEntries.GetChartValueItemFromX(TouchedPoint.X, frame, MaxItems); if (valueItems?.Any() != true) { return; } int index = 0; foreach (var item in valueItems) { var chartEntry = item.ChartValueItem; var nextChartEntry = item.NextChartValueItem; float y, points; if (nextChartEntry != null) { // Difference in value var diffVal = nextChartEntry.Value - chartEntry.Value; // Difference in Y position var diffY = nextChartEntry.Point.Y - chartEntry.Point.Y; // Difference in X position var diffX = nextChartEntry.Point.X - chartEntry.Point.X; var yValue = diffVal / diffY; var xValue = diffVal / diffX; // Current X position over first item var x = TouchedPoint.X - chartEntry.Point.X; points = x * xValue; y = (points / yValue) + chartEntry.Point.Y; } else { y = chartEntry.Point.Y; points = chartEntry.Value; } canvas.DrawSliderCircle(frame.GetInsideXValue(TouchedPoint.X), y, item.Color, SliderPointSize); float currentVal = 0; if (nextChartEntry != null) { try { currentVal = chartEntry.Value + (int)Math.Round(decimal.Parse(points.ToString()), 0, MidpointRounding.AwayFromZero); } catch (Exception ex) { ex.Print(); } if (TouchedPoint.X == chartEntry.Point.X) { currentVal = chartEntry.Value; } else if (TouchedPoint.X == nextChartEntry?.Point.X) { currentVal = nextChartEntry.Value; } } else { currentVal = chartEntry.Value; } string text = currentVal.ToString() + " " + this.VerticalUnit; canvas.DrawSliderValue( text, frame.GetInsideXValue(TouchedPoint.X), frame.Top, SliderDetailTextSize, SKColors.White, item.Color, SliderDetailPadding, SliderDetailMargin, MaxValue + " " + VerticalUnit, valueItems.Count, index, SliderDetailOrientation, frame, item.Parent?.UseDashedEffect == true); index++; } }