How do change to the color of a bar series programmatically?

2 posts, 0 answers
  1. Louay Jabry
    Louay Jabry avatar
    1 posts
    Member since:
    Mar 2005

    Posted 02 Apr 2012 Link to this post


    I need to programmatically create my barseries and assign a different color of my choosing for each series. In Line series, it is easy. I set the Stroke color. I couldn't find anything equivalent for the bar series.
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 03 Apr 2012 Link to this post

    Hello Louay,

    You can achieve the desired appearance by setting the BarSeries.DefaultVisualStyle property like this:
    BarSeries series = new BarSeries();
    series.DataPoints.Add(new CategoricalDataPoint() { Category = "C1", Value = 11 });
    series.DataPoints.Add(new CategoricalDataPoint() { Category = "C2", Value = 5 });
    series.DataPoints.Add(new CategoricalDataPoint() { Category = "C3", Value = 7 });
    series.DataPoints.Add(new CategoricalDataPoint() { Category = "C4", Value = 17 });
     
    Style style = new Style(typeof(Border));
    style.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.LightGray)));
    series.DefaultVisualStyle = style;
     
    RadChart1.Series.Add(series);

    Hope this helps.


    Regards,
    Giuseppe
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
Back to Top