Deleting the Default Legends and Adding Legends in Waterfall Chart with Aspose 24.x

Hi,

I am using aspose-cells-24.1.jar to create waterfall chart. I observe that the chart always comes up with default legends.

Increase, Decrease and Total, I am unable to remove these legends and add an custom legend.

tried with the sample code as shown below,

package aspose;

import com.aspose.cells.*;

public class WaterfallChart {

public static void main(String[] args) throws Exception {

	Workbook workbook = new Workbook();
	Worksheet worksheet = workbook.getWorksheets().get(0);
	
	Cells cells = worksheet.getCells();

	// Insert data
	cells.get("A1").putValue("Categories");
	cells.get("A2").putValue("Start");
	cells.get("A3").putValue("Positive Value 1");
	cells.get("A4").putValue("Negative Value 1");
	cells.get("A5").putValue("Positive Value 2");
	cells.get("A6").putValue("End");

	cells.get("B1").putValue("Values");
	cells.get("B2").putValue(0);
	cells.get("B3").putValue(20);
	cells.get("B4").putValue(-10);
	cells.get("B5").putValue(15);
	cells.get("B6").putValue(25);


	int chartIndex = worksheet.getCharts().add(ChartType.WATERFALL, 5, 0, 15, 5);
	Chart waterfallChart = worksheet.getCharts().get(chartIndex);
	waterfallChart.getNSeries().add("B2:B6", true);
	waterfallChart.getNSeries().setCategoryData("A2:A6");
	
	waterfallChart.getLegend().getLegendEntriesLabels().clear();
	
	waterfallChart.getNSeries().get(0).setName("Sample Legend");

	workbook.save("WaterfallChart.xlsx");
} 

}

Can you please help. Thanks in Advance.


This Topic is created by amjad.sahi using Email to Topic tool.

@vinaysrivatsacomm,

You can remove the Legend entries via Aspose.Cells. Simply replace the line:
i.e.,

waterfallChart.getLegend().getLegendEntriesLabels().clear();

with:

waterfallChart.setShowLegend(false); 

To add new legend entries, how could you do this in MS Excel manually? Could you please zip and attach your expected Excel file containing the chart with your desired legend entries? We will check on how to do it via Aspose.Cells for Java API. Please note, if a feature for Waterfall chart is supported in MS Excel manually, then Aspose.Cells can do this as well.

Thanks for the Response @amjad.sahi , It seems i am not able to set any custom values for the legends.Nor I can add any legend manually.

@vinaysrivatsacomm,

If you are unable to manually add or update legend entries for a Waterfall chart in MS Excel, Aspose.Cells will also be unable to do so. Please feel free to write back to us if you have any further queries or comments, and we will be happy to assist you soon.