Chart has no DataPoints ?
Hello,
I just wanted to add a differen color to a part of a chart with XLSIO.
The chart is created an filled with data without any problem. But if I try to set the color the chart remains on the standard-color.
So I found out that the chartserie has no datapoints in its collection.
This is the code I use:
Dim chart As IChartShape = xlsheet.Charts.Add()
chart.TopRow = xlsheet.Range("IssueStats").Row
chart.BottomRow = xlsheet.Range("IssueStats").Row + 18
chart.LeftColumn = xlsheet.Range("IssueStats").Column
chart.RightColumn = xlsheet.Range("IssueStats").Column + 13
chart.DataRange = Workbook.Worksheets("Infos").Range(Workbook.Worksheets("Infos").Range("IssueTypes").Row, 1, lastDataRow, 2)
chart.IsSeriesInRows = False
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Outside
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.IsValue = True
chart.HasLegend = False
'Farben setzen:
chart.Series(0).DataPoints(1).DataFormat.Fill.BackColor = Drawing.Color.Black
chart.Series(0).DataPoints(2).DataFormat.Fill.ForeColor = Drawing.Color.Black
Does anyone has an idea why the color can't be set ?
Thanks & Regards
Ralf
SIGN IN To post a reply.
9 Replies
JM
Johnson Monohar M
Syncfusion Team
March 7, 2013 05:26 AM UTC
Hi Ralf Steigele,
Thank you for using Syncfusion products.
It is possible to set colors for data labels with the following code snippet. Kindly follow the code snippets and let us know if it meets your requirement.
Dim chart As IChart = workbook.Charts(0)
chart.Series(0).DataPoints(0).DataLabels.Color = ExcelKnownColors.Red
chart.Series(0).DataPoints(1).DataLabels.Color = ExcelKnownColors.Green
chart.Series(0).DataPoints(2).DataLabels.Color = ExcelKnownColors.Blue
chart.Series(0).DataPoints(3).DataLabels.Color = ExcelKnownColors.Yellow
We have also provided a sample to illustrate this, which can be downloaded from the following link.
Sample Link : ChartDataPoints.zip
RS
Ralf Stiegele
March 7, 2013 08:49 AM UTC
Hi Johnson Monohar,
thank you for your advise. But I don't want to colour the datalabels I want to color the bars of the chart itself.
If I set it with:
chart.Series(0).DataPoints.DefaultDataPoint.DataFormat.Fill.BackColor = Drawing.Color.Red
all bars a coloured in red.
But I want them to have in different color like:
chart.Series(0).DataPoints(0).DataFormat.Fill.BackColor = Drawing.Color.Red
chart.Series(0).DataPoints(1).DataFormat.Fill.BackColor = Drawing.Color.Yellow
chart.Series(0).DataPoints(2).DataFormat.Fill.BackColor = Drawing.Color.Green
(But this doesn't change any colour - and I don't get it why)
RS
Ralf Stiegele
March 7, 2013 08:53 AM UTC
I uploaded a picture fo the result I expect:
http://www7.pic-upload.de/07.03.13/kqau7mjotlvw.jpg
JM
Johnson Monohar M
Syncfusion Team
March 11, 2013 05:06 AM UTC
Hi Ralf Steigele,
We are sorry for the inconvenience.
The "BackColor" property doesn't apply in datapoints. To apply custom color to the data points, kindly follow the below code snippets.
chart.Series(0).DataPoints(0).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Red
chart.Series(0).DataPoints(1).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Orange
chart.Series(0).DataPoints(2).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Tan
chart.Series(0).DataPoints(3).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Green
The output of the above code is shown in the below image.

Kindly apply the mentioned code snippets in your code and let us know if the provided solution helps.
Please let us know if you need any clarification.
Thanks,
Johnson
We are sorry for the inconvenience.
The "BackColor" property doesn't apply in datapoints. To apply custom color to the data points, kindly follow the below code snippets.
chart.Series(0).DataPoints(0).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Red
chart.Series(0).DataPoints(1).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Orange
chart.Series(0).DataPoints(2).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Tan
chart.Series(0).DataPoints(3).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Green
The output of the above code is shown in the below image.
Kindly apply the mentioned code snippets in your code and let us know if the provided solution helps.
Please let us know if you need any clarification.
Thanks,
Johnson
RS
Ralf Stiegele
March 11, 2013 09:28 AM UTC
Hello,
after adding the code to my solution the colour still doesn't change (remains default)
I also tried the ForeColor-Property - See the code I used:
chart.Series(0).DataPoints(0).DataFormat.Fill.ForeColor = System.Drawing.Color.Red
chart.Series(0).DataPoints(1).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Black
chart.Series(0).DataPoints(2).DataFormat.Fill.ForeColor = System.Drawing.Color.Red
chart.Series(0).DataPoints(3).DataFormat.Fill.ForeColorIndex = ExcelKnownColors.Black
But I still have the default colours set...
Regards
Ralf
RS
Ralf Stiegele
March 11, 2013 10:38 AM UTC
Hello,
I think the problem is: chart.IsSeriesInRows = False -> Because Excel doesn't seem to support different colours then.
(But you can set different colours in the Excel manually)
Regards
JM
Johnson Monohar M
Syncfusion Team
March 12, 2013 04:26 AM UTC
Hi Ralf Steigele,
We are sorry for the inconvenience.
We are able to set colors to the series if IsSeriesInRows property is FALSE or TRUE. To investigate further on this, we request you to create a new incident regarding this and update us a modified sample along with any excel file if used in the sample to reproduce the issue. This will help us to provide you a better solution.
Please let us know if you need any clarification.
Thanks,
Johnson
We are sorry for the inconvenience.
We are able to set colors to the series if IsSeriesInRows property is FALSE or TRUE. To investigate further on this, we request you to create a new incident regarding this and update us a modified sample along with any excel file if used in the sample to reproduce the issue. This will help us to provide you a better solution.
Please let us know if you need any clarification.
Thanks,
Johnson
RS
Ralf Stiegele
March 12, 2013 10:18 AM UTC
Hello,
I created a new Issue:
Regards
Ralf
JM
Johnson Monohar M
Syncfusion Team
March 14, 2013 04:03 AM UTC
Hi Ralf Steigele,
Thank you for creating new incident regarding this.
Regards,
Johnson
Thank you for creating new incident regarding this.
Regards,
Johnson
SIGN IN To post a reply.
- 9 Replies
- 2 Participants
-
RS Ralf Stiegele
- Mar 6, 2013 01:53 PM UTC
- Mar 14, 2013 04:03 AM UTC