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

Conditional Formatting for Chart?

3 Answers 332 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
hin
Top achievements
Rank 1
hin asked on 27 Jul 2011, 12:26 AM
I have a bar chart in my report,  X-axis is the employee name, Y-axis is the sales amount.   If sales amount over X, I would like to color the bar "Green".  If they are below X, color the bar "Red".  How can I do this?  I tried looking at Conditional Formatting but it's not working. 

Please guide me into right direction. 

Thanks!

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 27 Jul 2011, 05:03 PM
Hi Hin,

Currently our Chart item doesn't support conditional formatting. However you can create the chart programmatically and depending on the values set the series items' (bars') colors.

Check out the following code snippet that illustrates the suggested approach:

namespace Telerik.Reporting.Examples.CSharp
{
    using Telerik.Reporting.Charting;
    using System.Drawing;
  
    public partial class ProgramChart : Telerik.Reporting.Report
    {
        public ProgramChart()
        {
            InitializeComponent();
            InitializeChart();
        }
  
        private void InitializeChart()
        {
            this.chart1.PlotArea.EmptySeriesMessage.Appearance.Visible = true;
            this.chart1.PlotArea.EmptySeriesMessage.Visible = true;
              
            // Create a ChartSeries and assign its name and chart type
            var chartSeries = newChartSeries();
            chartSeries.Name = "Sales";
            chartSeries.Type = ChartSeriesType.Bar;
            // add new items to the series,
            // passing a value and a label string
            var item = newChartSeriesItem(120, "Internet");
            chartSeries.AddItem(140, "Retail");
            item.Appearance.FillStyle.FillType = Charting.Styles.FillType.Solid;
            item.Appearance.FillStyle.MainColor = Color.Red;
            chartSeries.AddItem(item);
            chartSeries.AddItem(35, "Wholesale");
  
            // add the series to the Chart Series collection
            this.chart1.Series.Add(chartSeries);
        }
    }
}

Additionally you may find useful Creating Chart Programmatically help article. 

Greetings,
Peter
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
hin
Top achievements
Rank 1
answered on 27 Jul 2011, 05:23 PM
Thank you for the reply.  Your example shows changing the formatting during the initialization stage. If I bind the SQL data to the chart via the wizard, how can I format the bar?  Can I use an IF statement during the data_binding event?  If so, can you provide a sample?
0
Peter
Telerik team
answered on 28 Jul 2011, 12:51 PM
Hi Hin,

If you bind the chart to a datasource, the chart will generate automatically the series items. Those automatically generated series items can't be modified. Thus our suggestion is based on the data programmatically to create all of the needed series items as we have illustrated in the previous post.

Greetings,
Peter
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
General Discussions
Asked by
hin
Top achievements
Rank 1
Answers by
Peter
Telerik team
hin
Top achievements
Rank 1
Share this question
or