We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Bar Chart Colors

Is it possible to change the colors of individual bars in a bar chart? For example, if ou wanted all negative values red and positive values green?

Thanks.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

If you want all negative values red and positive values green, you should set ASeries.Area.InvertIfNegative toTRUE, then set the foreground color and background color of the ASeries.Area.

See following codes:


Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
cells["A1"].PutValue(100);
cells["A2"].PutValue(200);
cells["A3"].PutValue(-200);
Charts charts = sheet.Charts;
int index = charts.Add(ChartType.Bar, 5, 5, 15, 10);
charts[index].NSeries.Add("A1:A3",true);
ASeries series = charts[index].NSeries[0];
series.Area.InvertIfNegative = true;
series.Area.ForegroundColor = System.Drawing.Color.Green;
series.Area.BackgroundColor = System.Drawing.Color.Red;
workbook.Save(@"C:\dest.xls");

Thank You & Best Regards,

Thanks. That seems to work. One more thing though. When I save the xls as a PDF the inverted bard are saved as the “positive” color?

Hi,

Thank you for considering Aspose.

After an initial test, we have found the issue, we will fix it soon.

Thank You & Best Regards,

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

We have fixed the issue regarding the Area.InvertIfNegative. Please try the attached latest fix.

Thank You & Best Regards,

The issues you have found earlier (filed as 6609) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Laurence.