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

Free Support Forum - aspose.com

Changing color of points in a single series

Hi Team,

I have only 1 series in my chart and 6 points for the series.
I want to set different color for all the 6 points.
Please find the below line of code for your reference:

chart1.getNSeries().get(0).getPoints().get(0).getArea().setForegroundColor(Color.fromArgb(134, 22, 139));

chart1.getNSeries().get(0).getPoints().get(1).getArea().setForegroundColor(Color.fromArgb(178, 29, 172));


But the above code is not working.
Could you please help me with sample code for the same.

Please find the attached excel sample file for your reference.

Thanks in advance!!!
Sanjeev

Hi,

Thanks for your posting and using Aspose.Cells.

Your code is correct. However, you need to set the formatting as custom. Please see the following code. It makes the 3rd data point as red colored. I have also attached the output excel file generated by it for your reference.

Java
String filePath = “F:\Shak-Data-RW\Downloads\Sample.XLSX”;

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.getWorksheets().get(0);

Chart chart = worksheet.getCharts().get(0);

Series srs = chart.getNSeries().get(0);

srs.getPoints().get(2).getArea().setFormatting(FormattingType.CUSTOM);
srs.getPoints().get(2).getArea().setForegroundColor(Color.getRed());

workbook.save(filePath + “.out.xlsx”);