Multi-Lines with SeriesMappings?

4 posts, 0 answers
  1. Enill
    Enill avatar
    41 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    Hi,
    is it possible to have multiple lines in a same chart using different seriesmapping object?

    To be more clear, i have 2 "List<StructXY>" where "StructXY" is a structure with two field(double x, double y).

    i have a "List<List<StructXY>>" collection and i want to bind 2 different seriesmapping(to draw two independant lines) in my chart based on the x and y value of eah collection.

    Thanks in advance if you can give me a simple working C# example.

  2. Enill
    Enill avatar
    41 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    Here is my test project(The reference to collectionindex = 1 just doesnt work at all):

    namespace seriesmapping_test 
        public partial class MainPage : UserControl 
        { 
            public struct structXY 
            { 
                public double valueX { getset; } 
                public double valueY { getset; } 
            } 
             
            public MainPage() 
            { 
                InitializeComponent(); 
     
                RadChart rc = new RadChart(); 
                List<List<structXY>> lstMain = new List<List<structXY>>(); 
                List<structXY> lst1 = new List<structXY>(); 
                List<structXY> lst2 = new List<structXY>(); 
     
                SeriesMapping sm1 = new SeriesMapping() 
                { 
                    SeriesDefinition = new LineSeriesDefinition() 
                    { 
                        ShowItemLabels = false 
                    } 
                }; 
                sm1.CollectionIndex = 1; 
                sm1.ItemMappings.Add(new ItemMapping("valueX", DataPointMember.XValue)); 
                sm1.ItemMappings.Add(new ItemMapping("valueY", DataPointMember.YValue)); 
     
                SeriesMapping sm2 = new SeriesMapping() 
                { 
                    SeriesDefinition = new BarSeriesDefinition 
                    { 
                        ShowItemLabels = false 
                    } 
                }; 
                sm2.CollectionIndex = 1; 
                sm2.ItemMappings.Add(new ItemMapping("valueX", DataPointMember.XValue)); 
                sm2.ItemMappings.Add(new ItemMapping("valueY", DataPointMember.YValue)); 
     
                rc.SeriesMappings.Add(sm1); 
                rc.SeriesMappings.Add(sm2); 
     
                for (int i = 0; i < 100; i++)  
                { 
                    lst1.Add(new structXY() { valueX = i, valueY = i }); 
                    lst2.Add(new structXY() { valueX = i, valueY = i ^ i }); 
                } 
     
                lstMain.Add(lst1); 
                lstMain.Add(lst2); 
     
                rc.PaletteBrushes.Add(new SolidColorBrush(Colors.Red)); 
                rc.PaletteBrushes.Add(new SolidColorBrush(Colors.Green)); 
                rc.ItemsSource = lstMain; 
     
                LayoutRoot.Children.Add(rc); 
            } 
        } 

  3. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 26 May 2010 Link to this post

    Hi Enill,

    I reviewed your code and I found two possible issues:
    1. CollectionIndex is set to 1 for both series definitions
    2. valueY = i ^ i -- this always sets valueY with 0, try changing it to i*i or i*5

    Greetings,
    Ves
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  4. Enill
    Enill avatar
    41 posts
    Member since:
    Apr 2010

    Posted 26 May 2010 Link to this post

    Hi,
    actually i noticed that i didnt posted the good code block, i apologies.

    The correct code block did'nt had the i ^ i , it was for a test purpose.

    Also, as you pointed, both collection were pointing to CollectionIndex = 1, it was my mistake, lack of awareness.

    Thanks you!
Back to Top