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.