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

Free Support Forum - aspose.com

Change column color of existing chart

Hi there… I have an excel file with existing chart with 3 columns, the problem is that i try to change a color column of existing chart by using aspose methods, but it’s not working i have tested all possible method but i cant change the color. can anyone help me?

Sorry this is my code:

public void setConditionalFormat(Workbook workbook){	
	Worksheet worksheet = workbook.getWorksheets().get("Report");
	Chart cumplCementoChart = worksheet.getCharts().get("Chart 2");
	//cumplCementoChart.getChartShape().
	SeriesCollection series = cumplCementoChart.getNSeries();
	//cumplCementoChart.getChartDataTable().set
	//SeriesCollection series = cumplCementoChart.getgetNSeries();
	Series s2 = series.get(0);

	//Color color = new Color();
	s2.getArea().setBackgroundColor(Color.getDarkGray());
	
	Series s1 = series.get(1);
	s1.getArea().setBackgroundColor(Color.getBeige());
	
	Iterator it = series.iterator();
	//System.out.println(series.getCategoryData());
	while(it.hasNext()){
		Series s = (Series) it.next();
		s.setMarkerBackgroundColor(Color.getRed());
		s.getArea().setBackgroundColor(Color.getRed());
		Style style = workbook.createStyle();
		style.setBackgroundColor(Color.getRosyBrown());
	
		//s.getMarker().get(0).setStyle(style);
		System.out.println(s.getName());
		System.out.println(s.getValues());
	}

}

@yisus,

Thanks for providing us sample code segment and details.

Please try using setForegroundColor method instead of setBackgroundColor in your code. If you still could not accomplish the task, kindly do provide your template file containing the column/bar chart, we will check it soon.

1 Like

thank you for your response Amjad…
I found the solution :slight smile: the problem was that i needed the points of the series and change their color. i leave my code here… it works!!

public void setConditionalFormat(Workbook workbook){
Worksheet worksheet = workbook.getWorksheets().get(“Report”);
Chart cumplCementoChart = worksheet.getCharts().get(“Chart 2”);//get chart
SeriesCollection series = cumplCementoChart.getNSeries();//get Series
Series s2 = series.get(0);//get serie to change
s2.getPoints().get(0).getArea().setForegroundColor(Color.getAqua());
s2.getPoints().get(1).getArea().setForegroundColor(Color.getAqua());
}

image.png (3.5 KB)

@yisus

Thanks for your posting and using Aspose.Cells.

It is good to know that you were able to sort out this issue. Let us know if you encounter any other issue, we will be glad to look into it and help you further.