ChartSeriesProvider - can I use a multibinding for my ItemsSource?

4 posts, 1 answers
  1. Joe
    Joe avatar
    86 posts
    Member since:
    Nov 2017

    Posted 03 Apr Link to this post

    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:ScatterLineSeries XValueBinding="X" YValueBinding="Y">
                <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  -->

    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}">

            <x:Type Type="core:IProfile" />
        <Setter Property="ItemsSource">
                <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   -->


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

        <tk:ChartSeriesProvider Source="{Binding Profiles}">
                <tk:ScatterSeriesDescriptor XValuePath="X" YValuePath="Y"
                                            Style="{StaticResource SeriesStyle}">


    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?





  2. Joe
    Joe avatar
    86 posts
    Member since:
    Nov 2017

    Posted 05 Apr in reply to Joe Link to this post

    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?
  3. Answer
    Vladimir Stoyanov
    Vladimir Stoyanov avatar
    680 posts

    Posted 08 Apr Link to this post

    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. 

    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.
  4. Joe
    Joe avatar
    86 posts
    Member since:
    Nov 2017

    Posted 08 Apr in reply to Vladimir Stoyanov Link to this post

    Cool no worries, thank you!
Back to Top