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.
Unfortunately, activation email could not send to your email. Please try again.

Chart has no DataPoints ?

Thread ID:

Created:

Updated:

Platform:

Replies:

107542 Mar 6,2013 08:53 AM Mar 14,2013 12:03 AM Windows Forms 9
loading
Tags: XlsIO
Ralf Stiegele
Asked On March 6, 2013 08:53 AM

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

Johnson Monohar M [Syncfusion]
Replied On March 7, 2013 12:26 AM

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

 

 


Ralf Stiegele
Replied On March 7, 2013 03:49 AM

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)


Ralf Stiegele
Replied On March 7, 2013 03:53 AM

I uploaded a picture fo the result I expect:

http://www7.pic-upload.de/07.03.13/kqau7mjotlvw.jpg

Johnson Monohar M [Syncfusion]
Replied On March 11, 2013 01:06 AM

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

Ralf Stiegele
Replied On March 11, 2013 05:28 AM

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

Ralf Stiegele
Replied On March 11, 2013 06:38 AM

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

Johnson Monohar M [Syncfusion]
Replied On March 12, 2013 12:26 AM

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

Ralf Stiegele
Replied On March 12, 2013 06:18 AM

Hello,

I created a new Issue:


Regards
Ralf

Johnson Monohar M [Syncfusion]
Replied On March 14, 2013 12:03 AM

Hi Ralf Steigele,

Thank you for creating new incident regarding this.

Regards,
Johnson

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;