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

RangeSeries LowBinding ValueConverter

1 Answer 114 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Philipp
Top achievements
Rank 1
Philipp asked on 06 Jul 2020, 07:34 AM

Hi there,

I'm trying to display a range series that is defined by a collection and a gap.

The ObservableCollection is defining the upper limit. The lower limit is defined by the upper limit minus the gap.

For this display I want to use a value converter that returns the lower limit for each upper limit.

<telerik:RadCartesianChart>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis />
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis/>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:RangeSeries ItemsSource="{Binding Path=SensorParameter.Range_UpperLimit}" HighBinding="Range_UpperLimit" CategoryBinding="RPM">
            <telerik:RangeSeries.LowBinding>
                <MultiBinding Converter="{StaticResource ConvertOKLowValue}">
                    <Binding Path="Range_UpperLimit" />
                    <Binding Path="Range_Gap" />
                </MultiBinding>
            </telerik:RangeSeries.LowBinding>
        </telerik:RangeSeries>
    </telerik:RadCartesianChart.Series>
</telerik:RadCartesianChart>

 

The SensorParameter struct looks like this:

01.public class RPM_Range : ObservableObject
02.{
03.    public float Range_Gap { get; set; }
04.    public ObservableCollection<Range_Limit> Range_UpperLimit { get; set; }
05.}
06. 
07.public class Range_Limit: ObservableObject
08.{
09.    public float RPM
10.    {
11.        get; set;
12.    }
13. 
14.    public float OK_Range_UpperLimit
15.    {
16.        get; set;
17.    }
18.}

 

The value converter is implemented like this:

01.public class RangeSeriesLowConverter : IMultiValueConverter
02.{
03.    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
04.    {
05.        double? _RangeUpperLimit = values[0] as double?;
06.        double? _RangeGap = values[1] as double?;
07.        if (_RangeUpperLimit - _RangeGap < 0)
08.            return 0;
09.       return _RangeUpperLimit - _RangeGap;
10.    }
11. 
12.    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
13.    {
14.        throw new NotImplementedException();
15.    }
16.}

 

UpperLimit binds correctly. But I'm not getting the binding to the lower limit correctly. While debugging the value converter is called, but the arguments are not passed correctly.

Is there a restriction using value converters for the low binding?

 

Thanks in advance for your help.

Kindly

Philipp

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 09 Jul 2020, 05:56 AM

Hello Philipp,

The binding properties like LowBinding, HighBinding, ValueBinding, etc., are expecting a DataPointBinding object. When the property is set in XAML it expects a string representing the name of the property that will be used for the corresponding binding. This is the the current code doesn't work.

To acheive your requirement you can use a GenericDataPointBinding for the LowBinding property. You can use the ValueSelector function of the generic binding to get the value that is currently calculated in your converter. The Create Data-Bound Chart article shows how to use the GenericDataPointBinding. 

Regards,
Martin Ivanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ChartView
Asked by
Philipp
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or