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

How to specify a PointTemplate for a Cartesian Series dynamically

3 Answers 202 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Kareema
Top achievements
Rank 2
Kareema asked on 08 Dec 2011, 09:17 AM
My ChartView has series which are created dynamically (programmatically). Each of these series need to be a colour that is also only known at runtime. How do I go about doing this?

3 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 09 Dec 2011, 05:17 PM
Hi Kareema,

The easiest way to achieve the desired effect would be to set the BarSeries.DefaultVisualStyle property instead of defining custom DataTemplate through the BarSeries.PointTemplate property:
// the default visual element for bar item is Border.
Style barStyle =
new Style(typeof(Border));
barStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Orange)));
 
BarSeries series = new BarSeries();
series.DefaultVisualStyle = barStyle;
 
series.DataPoints.Add(new CategoricalDataPoint() { Value = 20 });
series.DataPoints.Add(new CategoricalDataPoint() { Value = 30 });
series.DataPoints.Add(new CategoricalDataPoint() { Value = 50 });
series.DataPoints.Add(new CategoricalDataPoint() { Value = 10 });
series.DataPoints.Add(new CategoricalDataPoint() { Value = 10 });
 
RadChart1.Series.Add(series);



Greetings,
Giuseppe
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jinyan
Top achievements
Rank 1
answered on 09 Aug 2012, 12:26 AM
Is there another way to specify the line/fill color? I have very similar problem, except the type of my series is also dynamic (stored as CartesianSeries), and setting the color of Border for LineSeries doesn't seem to change the line color.

Never mind, I realized that since I was saving it as CartesianSeries I didn't have access to fields such as Stroke. I am now simply checking for each type and casting it.

Edit: I got everything except for BarSeries fill working. How do you specify the color of the barseries?
0
Lancelot
Top achievements
Rank 1
answered on 09 Aug 2012, 06:11 PM
Hi Jinyan,

You would actually be setting the fill of the rectangle in the DataTemplate for the bar as seen in this document.

Good luck,
Lancelot
Tags
ChartView
Asked by
Kareema
Top achievements
Rank 2
Answers by
Giuseppe
Telerik team
Jinyan
Top achievements
Rank 1
Lancelot
Top achievements
Rank 1
Share this question
or