@VaradS,
Here is sample code (using Aspose.Cells) of how you can create the Waterfall chart in the Excel template file you provided.
e.g.,
Sample code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
// Define data
String[] periods = {"PrevYear", "January", "February", "March", "April", "May", "June", "July", "August", "YTD"};
double[] savings = {-9, 1, 3, 4, -3, 2, 7, 3, 6, 23};
worksheet.getCells().get("B2").putValue("Periods");
worksheet.getCells().get("C2").putValue("Savings");
// Insert data into the worksheet
for (int i = 0; i < periods.length; i++) {
worksheet.getCells().get((i+2), 1).setValue(periods[i]);
worksheet.getCells().get((i+2), 2).setValue(savings[i]);
}
// Add a waterfall chart
int chartIndex = worksheet.getCharts().add(ChartType.WATERFALL, 5, 2, 25, 15);
Chart chart = worksheet.getCharts().get(chartIndex);
chart.getNSeries().add("C3:C12", true);
chart.getNSeries().setCategoryData("B3:B12");
chart.getNSeries().get(0).setName("=Sheet1!$C$2");
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
// Set chart title
chart.getTitle().setText("Waterfall Chart");
// Save the workbook
workbook.save("d:\\files\\out1.xlsx");
out1.zip (9.9 KB)
Now come to your desired legend customizations. How can you achieve the following legend customization tasks in MS Excel?
1. I want to change the name of the legend from Increase/Decrease to Positive/Negative.
2. Also, I would like to know if there is an option to hide the legend for Total alone without hiding the other 2 legends
I attempted to perform these tasks manually in MS Excel but was unable to do so. So, I cannot do the same with Aspose.Cells API. Would you kindly perform these tasks in MS Excel manually and create the chart with your desired legend customization, save the Excel file, and share the final file with us? We will then review how this can be done using the Aspose.Cells API.