Пример #1
0
        protected void DrawHorizontalLabels(SKCanvas canvas, SKRect frame, SKRect chart)
        {
            if (HorizontalLabelMode != LabelMode.None)
            {
                if (!string.IsNullOrEmpty(MinLabel) && !string.IsNullOrEmpty(MaxLabel))
                {
                    canvas.DrawHorizontalText(MinLabel, chart.Left, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Center, isBold: true);
                    canvas.DrawHorizontalText(MaxLabel, chart.Right, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Center, isBold: true);
                }
            }

            if (!string.IsNullOrEmpty(HorizontalUnit))
            {
                canvas.DrawHorizontalText(HorizontalUnit, chart.Right, frame.Bottom + (HorizontalLabelTextSize * 2), HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Left);
            }

            if (DisplayHorizontalValuesBySlider && IsSliderVisible)
            {
                var x = ChartType == ChartType.Linear ? TouchedPoint.X : chart.GetInsideXValue(TouchedPoint.X);

                var valueItems = ChartEntries.GetChartValueItemFromX(x, frame, MaxItems, ChartType == ChartType.Linear);

                var entry = valueItems?.FirstOrDefault()?.ChartValueItem;

                if (string.IsNullOrEmpty(entry?.Label))
                {
                    return;
                }

                x = ChartType == ChartType.Linear ? chart.GetInsideXValue(TouchedPoint.X) : entry.Point.X;

                canvas.DrawHorizontalText(entry.Label, x, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, SliderColor.ToSKColor(), SKTextAlign.Center, isBold: true);
            }
            else if (HorizontalLabelMode == LabelMode.All)
            {
                var items = ChartValuesDistinct;

                if (items?.Any() != true)
                {
                    return;
                }

                var points = ChartEntries.FirstOrDefault().Items.Select(x => x.Point).ToArray();

                for (int i = 0; i < items.Count(); i++)
                {
                    var entry = items.ElementAt(i);
                    var point = points[i];

                    if (string.IsNullOrEmpty(entry?.Label) || entry?.Label == MinLabel || entry?.Label == MaxLabel)
                    {
                        continue;
                    }

                    canvas.DrawHorizontalText(entry.Label, point.X, frame.Bottom + HorizontalLabelTextSize, HorizontalLabelTextSize, HorizontalLabelColor.ToSKColor(), SKTextAlign.Center);
                }
            }
        }