New to Telerik UI for Xamarin? Download free 30-day trial

ChartView for Xamarin.Android: LogarithmicAxis

RadCartesianChartView needs an axis that can represent the values of the data points. The base class for the axes that can represent value is NumericalAxis. It is an abstract class which extends the base CartesianAxis class and is used to represent the value of a data point.

The LogarithmicAxis is used to display values that cover several orders of magnitude in a more manageable way. This is a special NumericalAxis that transforms the actual values of the data points using logarithm function with a specific base. For example if the base of the logarithm is 10, then the axis will be scaled to show equally spaced powers of 10. The Richter scale and the Decibel scale are examples of logarithmic scale.

Example

You can read from the Getting Started page how to define the MonthResult type and declare the initData() method.

After you create the method for initialization of sample data, you can create a RadCartesianChartView with LogarithmicAxis by adding the following code to the onCreate() method of your Activity.

InitData();

RadCartesianChartView chartView = new RadCartesianChartView(this);

LineSeries lineSeries = new LineSeries();
lineSeries.CategoryBinding = new MonthResultDataBinding ("Month");
lineSeries.ValueBinding = new MonthResultDataBinding ("Result");
lineSeries.Data = (Java.Lang.IIterable)this.monthResults;
chartView.Series.Add(lineSeries);

CategoricalAxis horizontalAxis = new CategoricalAxis();
chartView.HorizontalAxis = horizontalAxis;

LogarithmicAxis verticalAxis = new LogarithmicAxis();
verticalAxis.LogarithmBase = 2;
chartView.VerticalAxis = verticalAxis;

ViewGroup rootView = (ViewGroup)FindViewById(Resource.Id.container);
rootView.AddView(chartView);

Customization

You can easily modify the base of the logarithmic function used to calculate the value by using the LogarithmBase property. The default value is 10, but in our example we have set it to 2, because our values are relatively small. You can also specify the exponent step between the axis ticks with the ExponentStep property. The default value of the exponent step is 0 which means that the axis itself will calculate an exponent step that will visualize the points in the best possible way.

In this article