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

Select series to plot - dynamic "ValueBinding"

1 Answer 72 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Marcin
Top achievements
Rank 1
Marcin asked on 09 Jul 2018, 11:04 AM

I have an object with some properties, such as:

public class Result
{
    public DateTime Date { get; set; }
    public Double Temperature { get; set; }
    public Double Humidity { get; set; }
}

 

I would like to have possibility to dynamically change series which I plot at the chart.

Eg. to have ComboBox with string items: "Temperature" and "Humidity" with binding SelectedItems={Binding SelectedSeriesName}
In ViewModel property "SelectedSeriesName"
In chart
<telerik:StepLineSeries ItemsSource="{Binding Results}" ValueBinding="{Binding SelectedSeriesName}" CategoryBinding="Date"/>

of course that is not possible due to ValueBinding must be string.

How can I make this scenario corect?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 10 Jul 2018, 02:05 PM
Hello Marcin,

Actually, the ValueBinding property is of type DataPointBinding. You can define it in XAML as string because it supports string to DataPointBinding type conversion. To achieve your requirement you can use an IValueConverter that converts the SelectedSeriesName to DataPointBinding. See this approach shown in the attached project. I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ChartView
Asked by
Marcin
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or