This is a migrated thread and some comments may be shown as answers.

Vertical axis custom labels width

3 Answers 99 Views
Chart - Xamarin.iOS
This is a migrated thread and some comments may be shown as answers.
Viollier
Top achievements
Rank 1
Viollier asked on 21 Nov 2016, 02:41 PM

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!

3 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 23 Nov 2016, 03:01 PM
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
0
Viollier
Top achievements
Rank 1
answered on 13 Dec 2016, 01:37 PM

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!

0
Accepted
Adrian
Telerik team
answered on 16 Dec 2016, 09:06 AM
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
Tags
Chart - Xamarin.iOS
Asked by
Viollier
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Viollier
Top achievements
Rank 1
Share this question
or