Free Support Forum - aspose.com

Chart generation

When I use your excel chart generation class I get what is in the attached document in the Aspose worksheet; however, the COM object built in to Visual Studio generates what’s in the COM worksheet.

What properties would I need to set when generating the chart using Aspose to get a chart similar to the one on the COM worksheet?

Hi,

Thanks for your question.

I think, you need to set Chart.RightAngleAxes property. Set it false and see the results. Let me know if it does not work.

That’s closer, but how do you set what excel built-in style it should use? Also if you look at the attached file there is a “1” below the horizontal axis and below that is the title. How do I force that “1” to be a different value? I want to have a Category Title and have this Axis labeled. Along the same line how do I move the Vertical Title to be just outside of the Plot Area.

Hi,

Please use Chart.getNSeries().setCategoryData method to change the labels and use Chart.getValueAxis/getCategoryAxis().getTitle().setX/Y() methods to change X/Y position of the Title on Value Axis or CategoryAxis.

Please see the code below.

Java


String path = “F:/Shak-Data-RW/Downloads/Example1.xls”;


Workbook workbook = new Workbook();

workbook.open(path);


//Put some value in C4 cell of “Test Data” worksheet

workbook.getWorksheets().getSheet(“Test Data”).getCells().getCell(“C4”).setValue(“My Test Value”);


//Access the chart on Aspose worksheet

Chart ch = workbook.getWorksheets().getSheet(“Aspose”).getCharts().getChart(0);


String str = ch.getNSeries().getCategoryData();

ch.getNSeries().setCategoryData("‘Test Data’!$C$4:$C$4");


ch.getCategoryAxis().getTitle().setText(“Category Title”);

ch.getValueAxis().getTitle().setText(“Value Title”);


workbook.save(path + “.out.xls”, FileFormatType.EXCEL97TO2003);

Thank you for all your help thus far, but do you know if there is a way to set the style of the chart to one of the built in styles for excel?

Hi,

I am afraid, this feature is not available. I have logged a request for it in our database.

This issue has been logged as a New Feature Request with id: CELLSNET-29411.

Hi,

After further investigation, I found, in xlsx format, you can use Chart.Style property to use built in style.

Please see the input and output file. Please see the screenshot and the code below.

C#


String path = “F:/Shak-Data-RW/Downloads/source.xlsx”;


Workbook workbook = new Workbook(path);


int chartSheetIdx = workbook.Worksheets.Add(SheetType.Chart);

Worksheet chartSheet = workbook.Worksheets[chartSheetIdx];

int chartIdx = chartSheet.Charts.Add(ChartType.Column3DClustered, 10, 10, 50, 50);

Chart chart = chartSheet.Charts[chartIdx];


chart.PlotArea.Area.ForegroundColor = Color.White;

chart.RightAngleAxes = false;


//Applying Style 10

chart.Style = 10;


chart.NSeries.Add("‘Test Data’!$A$2:$A$6", false);


workbook.Save(path + “.out.xlsx”, SaveFormat.Xlsx);

Screenshot:

The Chart.Style property doesn’t come up in the intelisense. Was this property available in Aspose.Cells 5.3.0.0?

Hi,

Please download the latest version: Aspose.Cells for .NET v6.0.1.1