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

ChartSeriesProvider - can I use a multibinding for my ItemsSource?

3 Answers 765 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Joe asked on 03 Apr 2020, 11:57 PM

I've long been showing a ScatterLineSeries on my RadCartesianChart that uses a MultiBinding in the ItemsSource.  I needed this multibinding because the underlying points are expressed in millimeters but the display can be in any units the user chooses and which the user can change. So I have to convert on the fly.  So I wrote a converter that takes 5 elements 

  1. An array of points to be converted
  2. The source X unit
  3. The source Y unit
  4. The destination X unit
  5. The destination Y unit.

It then returns an array of points converted to the appropriate units.  This works fine.  It looks like this:

 

 

<tk:RadCartesianChart.Series>
    <tk:ScatterLineSeries XValueBinding="X" YValueBinding="Y">
        <tk:ScatterLineSeries.ItemsSource>
            <MultiBinding Converter="{core:PointsLengthConverter}">
                <Binding Path="ProfilePoints" />
                <Binding Path="SystemService.Millimeter" />          <!-- Source X Unit  -->
                <Binding Path="SystemService.Millimeter" />          <!-- Source Y Unit  -->
                <Binding ElementName="Root" Path="LengthAxisUnit" /> <!-- Dest X Unit  -->
                <Binding ElementName="Root" Path="HeightAxisUnit" /> <!-- Dest Y Unit  -->
            </MultiBinding>
        </tk:ScatterLineSeries.ItemsSource>
    </tk:ScatterLineSeries>
</tk:RadCartesianChart.Series>


However now I need to show several plots on this graph, not just one.  But the number varies.  So I need to use a ChartSeriesProvider.  So I did, with a ScatterSeriesDescriptor.  At first it seemed to work -- I got my points -- but then I realized that it iis not converting my points anymore.  It is completely ignoring my "ItemsSource" binding in favor the of the "ItemsSourcePath" property in the descriptor.   

Here's what it looks like:  First I defined a style for each ScatterLineSeries

<Style x:Key="SeriesStyle" TargetType="{x:Type tk:ScatterLineSeries}">

    <d:Style.DataContext>
        <x:Type Type="core:IProfile" />
    </d:Style.DataContext>
 
    <Setter Property="ItemsSource">
        <Setter.Value>
            <MultiBinding Converter="{core:PointsLengthConverter DebugMode=True}">
                <Binding Path="ProfilePoints" />
                <Binding Source="{x:Static sdk:LengthUnit.Millimeter}" />  <!-- Source X Unit  -->
                <Binding Source="{x:Static sdk:LengthUnit.Millimeter}" />  <!-- Source Y Unit  -->
                <Binding ElementName="Root" Path="LengthAxisUnit" />       <!--  Dest X Unit   -->
                <Binding ElementName="Root" Path="HeightAxisUnit" />       <!--  Dest Y Unit   -->
            </MultiBinding>
 
        </Setter.Value>
    </Setter>
</Style>

 

Then, inside chart, I defined the seriesprovider and descriptor and used that style in it:

<tk:RadCartesianChart.SeriesProvider>
    <tk:ChartSeriesProvider Source="{Binding Profiles}">
        <tk:ChartSeriesProvider.SeriesDescriptors>
            <tk:ScatterSeriesDescriptor XValuePath="X" YValuePath="Y"
                                        ItemsSourcePath="Points"
                                        Style="{StaticResource SeriesStyle}">
            </tk:ScatterSeriesDescriptor>
        </tk:ChartSeriesProvider.SeriesDescriptors>
    </tk:ChartSeriesProvider>
</tk:RadCartesianChart.SeriesProvider>

 

Again, this mostly works.  My points get plotted.  My "SeriesStyle" even gets applied to the ScatterLineSeries (e.g. If I set the stroke to "Yellow" in that style, I see a yellow plotline).  But the final element of that style -- ItemsSource -- does NOT get applied.  I've tried putting a breakpoint inside the converter.  It never gets invoked.  So my points all remain in millimeters.

I took a closer look at ScatterSeriesDescriptor, hoping I could find a property that would let me achieve my MultiBinding.  I see XValuePath, YValuePath and ItemsSourcePath, and a few other properties ("TypeConverter", "TypePath", etc) but I cannot see any way to apply a MultiBinding to the series of points.

Can you suggest a way I can work around this?

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 05 Apr 2020, 04:42 PM
I should note:  I have been able to work around this by forcing my view model to expose an already-converted set of points.  But this relies on some code that's easy to break.  It would be better to be able to do the multi-binding just for simple reliability,.

So I'm not in a big rush for an answer but if you find the time, I would still be interested in knowing the answer to the question: Is it possible to use a multibinding for points in the SeriesProvider scenario?
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 08 Apr 2020, 03:32 PM

Hello Joe,

Thank you for the provided code snippets. 

It is not supported for the ItemsSource of the series to be set through the style applied to the series descriptor. The descriptor uses the ItemsSource extracted from the ItemsSourcePath and it takes precedence. 

That said, I am happy to hear that you have found another approach that is suitable for your scenario. Of course, don't hesitate to contact us again, if you have any other questions. 

Regards,
Vladimir Stoyanov
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.
0
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 08 Apr 2020, 04:27 PM
Cool no worries, thank you!
Tags
ChartView
Asked by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Vladimir Stoyanov
Telerik team
Share this question
or