Chart Series Values

I’d like to set the series in my chart to be a series of absolute values (not a range of cells).


Something like “={10, 20, 30}”.

The only way I can figure out how to do it is to add a fake NSeries made up of a cell range.

eg.

String fakeSeriesCellRange = “A1:C3”;

asposeChart.getNSeries().add(fakeSeriesCellRange , false );

asposeChart.getNSeries().get(0).setValues( “={10, 20, 30}” );
asposeChart.getNSeries().get(1).setValues( “={20, 40, 60}” );
asposeChart.getNSeries().get(2).setValues( “={30, 80, 120}” );

is there a better way to do this?

Thanks,
Jeff

Hi,

Thanks for your posting and using Aspose.Cells for Java.

We think, you are doing right. There is no better way of doing it. You will have to add fake series and then set your series values.

If you have any other question, please feel free to post, we will be glad to help you asap.

Hi Jeff,


I think you may try the following code, I am using static values to make it absolute. I have tested the code and it works fine.

Sample code:

Workbook workbook = new Workbook();
WorksheetCollection worksheets = workbook.getWorksheets();
worksheets.removeAt(0);
Worksheet dataSheet = worksheets.add(“Data”);
Worksheet chartSheet = worksheets.get(worksheets
.add(SheetType.CHART));
chartSheet.setName(“Chart”);
chartSheet.setSelected(true);

Chart chart = chartSheet.getCharts().get(chartSheet.getCharts().add(ChartType.BAR, 0, 0, 100, 100));

Cells cells = dataSheet.getCells();

int index = chart.getNSeries().add("{10,20,30}", true);
int index2 = chart.getNSeries().add("{60,70,90}", true);
chart.getNSeries().setCategoryData("{“A”,“B”,“C”}");
chart.getNSeries().get(index).setName(“MySeries”);
chart.getNSeries().get(index2).setName(“MySeries2”);

chart.setSizeWithWindow(true);
chart.setShowLegend(true);
workbook.save(“mychartseriesstatic.xls”);


Thank you.

Thanks for the replies. They were very helpful.


The issue seems to be with the ‘=’.
When calling setValues() on a Series object you have to include the ‘=’.
When calling add() on a SeriesCollection you have to exclude the ‘=’.

ie.

asposeChart.getNSeries().add( “{10, 20, 30}” , false );
// is the same as
asposeChart.getNSeries().get(0).setValues( “={10, 20, 30}” );

Maybe this specific case could be added to the documentation.

Thanks again!

Jeff

Hi,


Good to know that you got it working now. Yes, you are right, you will not use “=” while adding data series with static/absolute values. We will check if we can add it to the docs.

Thank you.