Change chart line color issue

Hi,

I trying to change chart line color at runtime. Here is the code I tried but does not work. Not sure where am I going wrong. Attached the template file.

----------------------------------------------------------------------------------------------------------------------------------------

string sFilePath = "ChartLine.xls";

string sOutputFilePath = "ChartLine_Output.xls";

Workbook oWB = new Workbook(sFilePath);

Worksheet oSheet = oWB.Worksheets["Sheet1"];

Aspose.Cells.Cells oCells = oSheet.Cells;

Chart oChart = oSheet.Charts["Chart 1"];

oChart.NSeries[1].SeriesLines.Color = System.Drawing.Color.Yellow;

oChart.NSeries[1].Area.ForegroundColor = System.Drawing.Color.Yellow; // tried using this also but does not work

oWB.Save(sOutputFilePath);

----------------------------------------------------------------------------------------------------------------------------------------

Thanks,

Hetal

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version: Aspose.Cells for .NET (Latest Version) .

You need to use the oChart.NSeries[n].Border.Color instead. We have tested it and it works fine.

Please see the following test code. I have attached the output xls file generated by it and the screenshot for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\ChartLine.xls”;


Workbook oWB = new Workbook(filePath);


Worksheet oSheet = oWB.Worksheets[“Sheet1”];


Aspose.Cells.Cells oCells = oSheet.Cells;


Chart oChart = oSheet.Charts[“Chart 1”];


//Set the second series line as Yellow color

oChart.NSeries[1].Border.Color = System.Drawing.Color.Yellow;


oWB.Save(filePath + “.out.xls”, SaveFormat.Excel97To2003);


Screenshot:

Thanks for quick reply,

I changed the code to use Border.Color and it worked properly. Note that, here I did not replace dll with the new version you specified. This is working with existing version also.

Thanks,

Hetal

het_hs:

Thanks for quick reply,

I changed the code to use Border.Color and it worked properly. Note that, here I did not replace dll with the new version you specified. This is working with existing version also.

Thanks,

Hetal

Hi,

Thanks for your feedback.

We are glad to know that existing version is also working fine with the given code. If you face any other issue, please feel free to post, we will be glad to assist you further.

And we wish you all have a great year in 2013. :)

Hi,

There is one small problem with this implementation. The border.color works properly with most of colors but it does not work sometimes with some of the RGB colors like,

R-0 G-51 B-153

R-79 G-130 B-195

Below is the code line changed from above code,

oChart.NSeries[0].Border.Color = System.Drawing.Color.FromArgb(0, 51, 153);

Thanks,

Hetal

Hi,


I think you may add / update your custom RGB color to the MS Excel color palette before specifying it as a border/line color in the chart’s series. For your information, for XLS (Excel 2003), there is a limitation and only 56 colors are there in the standard color palette, there is not such limitation for XLSX (Excel 2007/2010 formats) though. You may change the color palette for adding color by using Workbook.ChangePalette() method.

See the topic for your reference:
Colors and palette

Thank you.

hi,

I do not think it is because of the color restriction because when I use the same custom RGB color for text color or cell background color it takes properly and shows up correct color.

Thanks,

Hetal

Hi,


Please try the new fix/version: Aspose.Cells for .NET (Latest Version) . I have tested your case using it with your template file, it works fine. The line’s custom color is properly applied. Here is my updated code.

Sample code:

string filePath = @“e:\test2\ChartLine.xls”;
Workbook oWB = new Workbook(filePath);
Worksheet oSheet = oWB.Worksheets[“Sheet1”];
Aspose.Cells.Cells oCells = oSheet.Cells;
Chart oChart = oSheet.Charts[“Chart 1”];
//Set the second series line as custom RGB color
oChart.NSeries[0].Border.Color = System.Drawing.Color.FromArgb(0, 51, 153);
oWB.Save(filePath + “out.xls”, SaveFormat.Excel97To2003);

I have attached the output file here for your reference.

Thank you.

hi,

2 points for you here,

1) The attached file in your reply does not have correct color. Your output file has 0, 51, 102 instead of 0, 51, 153. I reported the same problem. I am not sure if you attached wrong output file.

2) The link of new fix version is in Java. My project is in .Net.

Pls check the output file first because I think the output itself is wrong.

Thanks,

Hetal

Hi,


1) Well, I tried to evaluate the output Excel file’s chart line color, I think it is fine, the first series color is OK, it is fine as R=0, G=51, B=153, I could not notice the issue. Could you check and compare the first’ series color values in some photo editor package e.g Adobe Photo shop and give us screen shots for the issue. We will check it soon.

2) We are sorry for your inconvenience. Please download and try our latest fix/version for .NET now: Aspose.Cells for .NET (Latest Version)