Logarithmic Chart in iOS

2 Answers 91 Views
Chart - Xamarin.iOS
Marco
Top achievements
Rank 1
Iron
Marco asked on 28 Jun 2021, 01:18 PM

Hi,

i am trying to create a graph, as can be seen in picture Chart.png.

But i found no property to set the start value of the logarithmic axis (default start value is 1 but i need 125).

How can i change the display range of the TKChartNumericAxis? And it is possible to invert the y axis (like in the screenshot)?

My current code:
var chart = new TKChart
{
    XAxis = new TKChartLogarithmicAxis
    {
        LogarithmBase = 2
    },
    YAxis = new TKChartNumericAxis(NSObject.FromObject(-10), NSObject.FromObject(120)),
    Frame = StackLayout.Bounds.ToRectangleF()
};

chart.Title.Hidden = true;
chart.Legend.Hidden = true;

var list = new NSObject[]
{
    new TKChartDataPoint(new NSNumber(500), new NSNumber(70)),
    new TKChartDataPoint(new NSNumber(1000), new NSNumber(40)),
    new TKChartDataPoint(new NSNumber(2000), new NSNumber(60)),
    new TKChartDataPoint(new NSNumber(4000), new NSNumber(50))
};

var series = new TKChartLineSeries(list);
chart.AddSeries(series);

2 Answers, 1 is accepted

Sort by
0
Accepted
Didi
Telerik team
answered on 30 Jun 2021, 01:56 PM

Hello,

Let me get straight to the questions:

Start value for the logarithmic axis: You can use the axis Range property.

for example:

TKChartLogarithmicAxis yAxis = new TKChartLogarithmicAxis();
			xAxis.LogarithmBase = 2;
			xAxis.Range = new TKRange(new NSNumber(125), new NSNumber(1200));
			xAxis.Position = TKChartAxisPosition.Bottom;
			chart.XAxis = xAxis;

 

same for numerical axis:

TKChartNumericAxis yAxis = new TKChartNumericAxis ();
yAxis.Range = new TKRange (new NSNumber (-10), new NSNumber (100));

Invert the y axis -> I am afraid I couldn't find a solution for this. You can check the native ios chart documentation for more details about the axis features: https://docs.telerik.com/devtools/xamarin/nativecontrols/ios/chart/axes/axes  

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Marco
Top achievements
Rank 1
Iron
answered on 01 Jul 2021, 09:11 AM

Hello Didi,

thank you for your answers. I overlooked the "Range" property and this is the solution for my first question.

For the second question i have found a workaround:

  • invert the range (in this case -120 to 10)
  • set axis position to top
  • add a custom label formatter that multiplies the value by -1

Regards,

Marco

Didi
Telerik team
commented on 01 Jul 2021, 10:53 AM

Hello Marco, 

I am glad to hear you have found a solution using the axis features. Thank you for sharing this solution with us. 
Tags
Chart - Xamarin.iOS
Asked by
Marco
Top achievements
Rank 1
Iron
Answers by
Didi
Telerik team
Marco
Top achievements
Rank 1
Iron
Share this question
or