Problem with dynamically adding series

7 posts, 1 answers
  1. Nathan
    Nathan avatar
    8 posts
    Member since:
    May 2009

    Posted 04 May 2009 Link to this post

    Hello,

    I'm having an issue with trying to dynamically add series.  For example, I have a for loop that cycles through a few items, with each item being a series I want added.  I've tried various different ways of doing this, but what happens is every time I add a series dynamically the app goes white and crashes in run time.  

    The reason I'm doing this is I need different colors based on certain values and I'm not sure if there is a way to change the color of a series item.  Here is some example code:

    foreach (MyClass topic in topics) 
                { 
                    Telerik.Windows.Controls.Charting.DataSeries post_series = new Telerik.Windows.Controls.Charting.DataSeries(); 
                    post_series.Definition.ShowItemToolTips = true
                    post_series.Definition.ShowItemLabels = true
                    post_series.Definition = new BubbleSeriesDefinition(); 
                     
                    post_series.Add(new DataPoint { YValue = topic.Posts, LegendLabel = topic.Author, Label = topic.Author, XValue = topic.Comments, BubbleSize = (topic.Rank + 5)}); 
                    SolidColorBrush brushcolor = new SolidColorBrush(); 
                    if (topic.Positive == 0 && topic.Negative == 0) 
                    { 
                        brushcolor = new SolidColorBrush(Colors.Blue);                     
                    } 
                    else if (topic.Positive == topic.Negative) 
                    { 
                        brushcolor = new SolidColorBrush(Colors.Yellow);                     
                    } 
                    else if (topic.Positive > topic.Negative) 
                    { 
                        brushcolor = new SolidColorBrush(Colors.Green);                     
                    } 
                    else 
                    { 
                        brushcolor = new SolidColorBrush(Colors.Red);                     
                    } 
                    chart.DefaultView.ChartArea.DataSeries.Add(post_series); 
                    
                } 

    Thoughts?  Thanks for your time.


  2. Nathan
    Nathan avatar
    8 posts
    Member since:
    May 2009

    Posted 04 May 2009 Link to this post

    I think I found another clue.

    In a seperate chart I had a dynamic data set, and one of the series had only one data point (it was an area line chart).  This caused the whole app to crash.  Is there an issue with a data series with only one point?

    The thing I was trying to do above with the multiple series each had only one data point in each series.
  3. Answer
    Ves
    Admin
    Ves avatar
    2926 posts

    Posted 05 May 2009 Link to this post

    Hello Nathan,

    It seems you have hit a bug in RadChart. I was able to reproduce it with TotalSeriesAnimationDuration set to a non-zero timespan.  The fix will be included in the next version of the control and for the time being, please use ItemAnimationDuration or disable the animations. I have updated your Telerik points.

    As for assigning individual colors to the series items -- you can check this online example.

    Kind regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Nathan
    Nathan avatar
    8 posts
    Member since:
    May 2009

    Posted 05 May 2009 Link to this post

    Edit:  Whops, misread what you said, I will try out the animation change.

    Anyways I tried out my theory and it worked:

    foreach (MyClass topic in topics)  
                {  
                    Telerik.Windows.Controls.Charting.DataSeries post_series = new Telerik.Windows.Controls.Charting.DataSeries();  
                    post_series.Definition.ShowItemToolTips = true;  
                    post_series.Definition.ShowItemLabels = true;  
                    post_series.Definition = new BubbleSeriesDefinition();  
                      
                    post_series.Add(new DataPoint { YValue = topic.Posts, LegendLabel = topic.Author, Label = topic.Author, XValue = topic.Comments, BubbleSize = (topic.Rank + 5)});  
    post_series.Add(new DataPoint { YValue = topic.Posts, LegendLabel = topic.Author, Label = topic.Author, XValue = topic.Comments, BubbleSize = (topic.Rank + 5)});  
                    SolidColorBrush brushcolor = new SolidColorBrush();  
                    if (topic.Positive == 0 && topic.Negative == 0)  
                    {  
                        brushcolor = new SolidColorBrush(Colors.Blue);                      
                    }  
                    else if (topic.Positive == topic.Negative)  
                    {  
                        brushcolor = new SolidColorBrush(Colors.Yellow);                      
                    }  
                    else if (topic.Positive > topic.Negative)  
                    {  
                        brushcolor = new SolidColorBrush(Colors.Green);                      
                    }  
                    else  
                    {  
                        brushcolor = new SolidColorBrush(Colors.Red);                      
                    }  
                    chart.DefaultView.ChartArea.DataSeries.Add(post_series);  
                     
                }  

    As you can see I just added the same data point twice, and the page loaded without errors.  That was it.  It's a waste of resources sure but at least it's a usable work around.

    Anyways thanks!
  5. Nathan
    Nathan avatar
    8 posts
    Member since:
    May 2009

    Posted 05 May 2009 Link to this post

    Your work around did the trick, thanks!
  6. Alexy
    Alexy avatar
    11 posts
    Member since:
    May 2009

    Posted 20 May 2009 Link to this post

    Sometimes, when I am trying to clean the data series, the system crushes.

    RadControl1.DefaultView.ChartArea.DataSeries.Clear();

    I am using the Silverlight, I have a TabControl and a couple of TabItems, where each TabItem has its Chart control. For example, Linear, Spline, Bar, Range.
    When I select a new tab, I try to clean the DataSeries and fill it with new data.

    But sometimes I've got an error, something like 'Internal Error' on DefaultView.ChartArea.DataSeries.Clear();.
    Any ideas?
  7. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 25 May 2009 Link to this post

    Hi Alexy,

    Here is the answer to the other forum thread you have started:

    While we are aware of a similar issue with Stick and CandleStick series and the fix for it will be included in service pack 2 release, expected later today, we have not been able to reproduce it with Line, Spline, Bar or Range series. Can you provide more details or send us a small example, showing this? Thanks.

    Kind regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top