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

Problem with dynamically adding series

6 Answers 231 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 04 May 2009, 02:02 PM
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.


6 Answers, 1 is accepted

Sort by
0
Nathan
Top achievements
Rank 1
answered on 04 May 2009, 04:34 PM
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.
0
Accepted
Ves
Telerik team
answered on 05 May 2009, 10:24 AM
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.
0
Nathan
Top achievements
Rank 1
answered on 05 May 2009, 01:17 PM
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!
0
Nathan
Top achievements
Rank 1
answered on 05 May 2009, 01:25 PM
Your work around did the trick, thanks!
0
Alexy
Top achievements
Rank 1
answered on 21 May 2009, 02:56 AM
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?
0
Ves
Telerik team
answered on 25 May 2009, 07:48 AM
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.
Tags
Chart
Asked by
Nathan
Top achievements
Rank 1
Answers by
Nathan
Top achievements
Rank 1
Ves
Telerik team
Alexy
Top achievements
Rank 1
Share this question
or