How to specify a PointTemplate for a Cartesian Series dynamically

4 posts, 1 answers
  1. Kareema
    Kareema avatar
    17 posts
    Member since:
    Aug 2011

    Posted 08 Dec 2011 Link to this post

    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?
  2. Answer
    Giuseppe avatar
    2363 posts

    Posted 09 Dec 2011 Link to this post

    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 });

    the Telerik team

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

  3. Jinyan
    Jinyan avatar
    23 posts
    Member since:
    Jul 2012

    Posted 08 Aug 2012 Link to this post

    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?
  4. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 09 Aug 2012 Link to this post

    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,
Back to Top