Change each Bar color in RadCartesianChart

2 posts, 0 answers
  1. Alberto
    Alberto avatar
    26 posts
    Member since:
    Nov 2012

    Posted 18 Oct 2013 Link to this post

    Hi,

    I am creating a RadCartesianChart and adding bar series this way:

    chartSafety.VerticalAxis = new LinearAxis();
                chartSafety.HorizontalAxis = new CategoricalAxis();
     
                DataTable dtSafety = new DataTable("DATA");
     
                dtSafety.Columns.Add(new DataColumn("Name", typeof(string)));
                dtSafety.Columns.Add(new DataColumn("ValueBar", typeof(double)));
     
                dtSafety.Rows.Add(new object[] { "Value1", 70 });
                dtSafety.Rows.Add(new object[] { "Value2", 15 });
                dtSafety.Rows.Add(new object[] { "Value3", 34 });
                dtSafety.Rows.Add(new object[] { "Value4", 87 });
                dtSafety.Rows.Add(new object[] { "Value5", 45 });
                dtSafety.Rows.Add(new object[] { "Value6", 22 });
                dtSafety.Rows.Add(new object[] { "Value7", 33 });
                dtSafety.Rows.Add(new object[] { "Value8", 65 });
                dtSafety.Rows.Add(new object[] { "Value9", 19 });
                dtSafety.Rows.Add(new object[] { "Value10", 41 });
                 
     
                BarSeries barSer = new BarSeries();
     
    foreach (DataRow drSafety in dtSafety.Rows)
                {
                    barSer.DataPoints.Add(new CategoricalDataPoint() { Category = drSafety["Name"], Label = string.Format("{0:N}", drSafety["ValueBar"]), Value = double.Parse(drSafety["ValueBar"].ToString()) });
                  
                     
                }
                 
                chartSafety.Series.Clear();
                chartSafety.Series.Add(barSer);

    Is there a way to change the color for each bar in the series while I am creating each data point?

    Regards,

    Alberto
  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 21 Oct 2013 Link to this post

    Hi Alberto,

     There are various ways to colorize bar series as you'll find in our documentation here. In brief you might either create your own palette of brushes or create custom styles for the individual bar items depending on your custom logic (achievable via Custom Item Style delegate).

    Regards,
    Evgenia
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top