Vertical axis custom labels width

4 posts, 1 answers
  1. Viollier
    Viollier avatar
    5 posts
    Member since:
    Jul 2016

    Posted 21 Nov 2016 Link to this post

    Hi,

    i have a Xamarin iOS chart that uses custom labels. My issue is the width of the Vertical axis labels: for a certain data set, the default vertical labels look like "0.22, 0.4599999999, 1.2999999999...."; when i set the custom labels to "0.1,  0.4, 5 ....", the width of the labels remains very big, just as if the large labels were still showing. The same thing happens if i set the range to something like "0.4599999999...." - the custom labels will have a lot of padding.

    How can i force the labels to resize?

    Thanks!

  2. Adrian
    Admin
    Adrian avatar
    174 posts

    Posted 23 Nov 2016 Link to this post

    Hi, Viollier,

    Thank you for writing.
    Could you, please, send me a code snippet of your setup so I could investigate the issue further? Thank you in advance for your cooperation.

    Regards,
    Adrian
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Viollier
    Viollier avatar
    5 posts
    Member since:
    Jul 2016

    Posted 13 Dec 2016 in reply to Adrian Link to this post

    Hi Adrian,

    here is my code:

    Initially:
    private void SetupChart()
            {
                Chart = new TKChart(CGRect.Inflate(ChartContainerView.Bounds, 0, 0);
                Chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                Chart.Delegate = chartDelegate;
                ChartContainerView.AddSubview(Chart);
            }

    Then, when the ChartModel becomes available, i start customising it:


            Chart.AllowAnimations = true;

            Chart.BeginUpdates();

            Chart.RemoveAllData();           
            var dataPoints = GetDataPoints();
            var series = new TKChartLineSeries(dataPoints.ToArray());
            StyleSeries(series);
            Chart.AddSeries(series);
            var axis = new TKChartDateTimeAxis(ChartModel.MinDate, ChartModel.MaxDate);
            AdjustXAxis(axis);
            Chart.XAxis = axis;
            AdjustYAxisRange();

            Chart.EndUpdates();

            AddChartBandAnnotation();
            StyleChart();

    Here are the details of the methods i am using:

        void StyleSeries(TKChartLineSeries series)
        {
            ........
            palette settings, stroke colors, etc
            ........
        }

        void StyleChart()
        {
            Chart.GridStyle.HorizontalLinesHidden = true;
            Chart.GridStyle.HorizontalFill = null;
            Chart.GridStyle.HorizontalAlternateFill = null;
            Chart.GridStyle.VerticalLinesHidden = false;
            Chart.GridStyle.VerticalFill = null;
            Chart.GridStyle.VerticalAlternateFill = null;

        }

        void AdjustYAxisRange()
        {
            Range axisRange = ChartModel.RoundedVerticalAxisRange();
            Chart.YAxis.Range = new TKRange(new NSNumber(axisRange.Min), new NSNumber(axisRange.Max));

            //force the axis not to display any default labels
            ((TKChartNumericAxis)Chart.YAxis).MajorTickInterval = axisRange.Span;
        }

        //Call this after EndUpdates();
        void AddChartBandAnnotation()
        {
            Chart.RemoveAllAnnotations();

            var range = GetChartBandRange();
            if (range != null)
            {
                var fillColor = new UIColor(0.83f, 0.92f, 0.88f, 0.6f);
                var strokeColor = new UIColor(0.6f, 0.85f, 0.76f, 0.8f);
                var fill = new TKSolidFill(fillColor);
                var stroke = new TKStroke(strokeColor, 1.5f);
                var annotation = new TKChartBandAnnotation(range, Chart.YAxis, fill, stroke);
                Chart.AddAnnotation(annotation);
            }

            var labels = GetVerticalAxisLabels();
            if (labels.Count > 0)
            {
                Chart.YAxis.CustomLabels = labels;
                Chart.YAxis.Style.LabelStyle.TextAlignment = TKChartAxisLabelAlignment.Left;
                Chart.YAxis.Style.LabelStyle.FirstLabelTextAlignment = TKChartAxisLabelAlignment.Left;
                Chart.YAxis.Style.LabelStyle.TextOffset = new UIOffset(2, 0);
                Chart.YAxis.Style.LabelStyle.FirstLabelTextOffset = new UIOffset(2, 0);

                Chart.YAxis.Style.LabelStyle.TextHidden = false;

            }
            else
            {
                Chart.YAxis.Style.LabelStyle.TextHidden = true;
            }


            Chart.YAxis.AllowPan = false;
            Chart.YAxis.AllowZoom = false;
            AdjustYAxisRange();
            Chart.Update();

        }

    Thanks!

  4. Answer
    Adrian
    Admin
    Adrian avatar
    174 posts

    Posted 16 Dec 2016 Link to this post

    Hello Viollier,

    Thank you for the code snippet. I can confirm that this issue exists in TKChart. The width of the axis is measured considering the width of the default labels not the custom ones. I logged this issue and it will be addressed in a future release. I also updated your Telerik points for reporting this issue.
    A possible workaround is to use the axis' LabelFormat property to format the labels with 0 digits after the decimal point. I hope this helps.

    Regards,
    Adrian
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top