We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Colors for bar chart

I'm creating the bar chart using the code below. I simply need to know how to set the colors for the different areas of each bar.
Any ideas?

Thanks

Carl

'Adding a New(Embedded chart) to the WorkoWS
Dim shape As IChartShape = oWS.Charts.Add()shape.ChartType = ExcelChartType.Column_Stacked'Specify the data range.shape.DataRange = oWS.Range("B" + sTopRow.ToString + ":D" + (sRow - 1).ToString)

'Setting the Serie Names in a Legend
Dim serieOne As IChartSerie = shape.Series(0)
serieOne.Name = "Completed"
serieOne.CategoryLabels = oWS.Range("A" + sTopRow.ToString + ":A" + (sRow - 1).ToString)
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValue = True
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = False

Dim serietwo As IChartSerie = shape.Series(1)
serietwo.Name = "Planned/Current"
serietwo.CategoryLabels = oWS.Range("B" + sTopRow.ToString + ":B" + (sRow - 1).ToString)
serietwo.DataPoints.DefaultDataPoint.DataLabels.IsValue = True
serietwo.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = False

Dim seriethree As IChartSerie = shape.Series(2)
seriethree.Name = "Overdue"
seriethree.CategoryLabels = oWS.Range("C" + sTopRow.ToString + ":C" + (sRow - 1).ToString)
seriethree.DataPoints.DefaultDataPoint.DataLabels.IsValue = True
seriethree.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = False

'Set title to the chart
shape.ChartTitle = oDT.Rows(0)("DomainName").ToString
shape.ChartTitleArea.Bold = True
shape.ChartArea.IsBorderCornersRound = True
shape.Legend.Position = ExcelLegendPosition.Bottom

1 Reply

MW Melba Winshia Syncfusion Team January 30, 2007 11:13 AM UTC

Hi Carl,

Could you please use the following code snippet to set the colors for the different areas of each bar.

Here is the code snippet:

[C#]

//First Serie
IChartSerie serieOne = shape.Series[0];

//Color of first serie
serieOne.DataPoints.DefaultDataPoint.DataFormat.AreaProperties.ForegroundColorIndex=ExcelKnownColors.Lavender;

//Second Serie
IChartSerie serietwo = shape.Series[1];

//Color of Second serie
serietwo.DataPoints.DefaultDataPoint.DataFormat.AreaProperties.ForegroundColor=System.Drawing.Color.Orange;

// Third Serie
IChartSerie seriethree = shape.Series[2];

//Color of third serie
seriethree.DataPoints.DefaultDataPoint.DataFormat.AreaProperties.ForegroundColor=System.Drawing.Color.Purple;

[VB.NET]

'First Serie
Dim serieOne As IChartSerie = shape.Series(0)

'Color of first serie
serieOne.DataPoints.DefaultDataPoint.DataFormat.AreaProperties.ForegroundColorIndex=ExcelKnownColors.Lavender

'Second Serie
Dim serietwo As IChartSerie = shape.Series(1)

'Color of Second serie
serietwo.DataPoints.DefaultDataPoint.DataFormat.AreaProperties.ForegroundColor=System.Drawing.Color.Orange

' Third Serie
Dim seriethree As IChartSerie = shape.Series(2)

'Color of third serie
seriethree.DataPoints.DefaultDataPoint.DataFormat.AreaProperties.ForegroundColor=System.Drawing.Color.Purple

Here is the sample for your reference:

Chart.zip

Please have a look at this sample and let me know if this helps you.

Thanks for your interest in Syncfusion products.

Best Regards,
Melba


Loader.
Live Chat Icon For mobile
Up arrow icon