Dynamically allow user to switch between Linear and Logarithmic Axis

1 Answer 141 Views
ChartView
sumu
Top achievements
Rank 1
sumu asked on 09 Oct 2021, 03:48 AM

Hello

 

I am showing a RadChartView which has a bar series.

I have varying data and sometimes logarithmic is better and sometimes linear axis is better.

How can I provide a button to dynamically switch between Linear Axis and Logartihmic Axis on the vertical axis?

I prefer using XAML and data binding in XAML. is this possible?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 13 Oct 2021, 12:00 PM

Hello Subash,

You should be able to use a command and a property in the view model, along with axes defined in the Resources of the view. This way you can use data bindings and triggers to update the VerticalAxis and HorizontalAxis properties of the chart. However, I won't recommend this approach because removing and re-adding the same axis instance may lead to visual glitches. Instead, I would suggest you to use code-behind and create a new instance of the corresponding axis, each time you need to switch. 

If you insist on avoiding code-behind, one way would be to use an IValueConverter with the HorizontalAxis and VerticalAxis properties. In this case, when a property in the view model changes (on a button's command for example), you can create a new instance of the corresponding chart axis. For example:

<telerik:RadCartesianChart HorizontalAxis="{Binding CurrentHorizontalAxisType, Converter={StaticResource AxisTypeToAxisControlConverter}}" />

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
	var axisType = (string)value;
	if (axisType == "Linear")
	{
               return new LinearAxis();
	}
	else
	{
               return new LogarithmicAxis();
	}
}

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ChartView
Asked by
sumu
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or