Set X Axis for chart for TIME SCALE category while using Aspose.Cells for Java

Hi,
Could you help me for chart creation in Aspose cells ?

I have read some post about this subject but,
scale parameters in CategorisAxis seems not apply.

here my piece of code :

chart.setLegendShown(isShowLegend());
chart.setAutoScaling(false); //in the excel chart, this option is not desactivated!
CategoryAxis categoryAxis = chart.getCategoryAxis();
categoryAxis.setCategoryType(CategoryType.TIME_SCALE);
categoryAxis.setMajorUnitScale(TimeUnit.YERAS);
categoryAxis.setMajorUnit(1);
categoryAxis.setMinValue(40909); //date value for excel (01/01/2012)
// no title
categoryAxis.getTitle().setText("");


I just want display in X axis, all years by one years step but the axis scale is always the same.
See the attachment screenshot for data and result.
Aspose version for java : aspose-cells-1.9.4.jar

Thank!!


Hi,

Could you post your template file here, we will check it soon.

Thank you.

I don’t have a excel template, i create the excel file from scratch.
Like this :
workbook = new Workbook();


Thank!


Hi,

Would you please try our latest version 1.9.5? We tested it with your code, the created chart's X axis does increase by one year step. Following is my test code.

Workbook wb = new Workbook();
Cells cells = wb.getWorksheets().getSheet(0).getCells();
Style style = wb.createStyle();
style.setNumber(15);
cells.getColumn(0).setStyle(style);
for(int i=0; i<8; i++)
{
cells.getCell(i, 0).setValue(39465 + i*120 + (i%4)*30);
cells.getCell(i, 1).setValue(i%4);
}
Chart chart = wb.getWorksheets().getSheet(0).getCharts().addChart(ChartType.LINE, 10, 3, 18, 8);
chart.getNSeries().add("B1:B8", true);
chart.getNSeries().setCategoryData("A1:A8");
chart.setAutoScaling(false); //in the excel chart, this option is not desactivated!
CategoryAxis categoryAxis = chart.getCategoryAxis();
categoryAxis.setCategoryType(CategoryType.TIME_SCALE);
categoryAxis.setMajorUnitScale(TimeUnit.YERAS);//MONTHS);//
categoryAxis.setMajorUnit(1);
categoryAxis.setMinValue(39479);
categoryAxis.getTitle().setText("");
wb.save("t.xls");

To show only year without month displat in X axis, please replace the red part with following:

categoryAxis.setBaseUnitScale(TimeUnit.YERAS);

If it is different from your code and result, please give us your code to create the file, we will check it soon, thank you.

Hi,
i have test your code with my aspose version.
it’good.
The problems come from the chart type.
in my code : ChartType.SCATTER,
in your code : ChartType.LINE,

In excel for a scatter chart, it’s not possible to specify base unit.
I found an other solution






Hi,
i have test your code with my aspose version.
it’good.
The problems come from the chart type.
in my code : ChartType.SCATTER,
in your code : ChartType.LINE,

In excel for a scatter chart, it’s not possible to specify base unit.
I found an other solution

Thank for your answer.




Hi,

Yes, MS Excel does not allow this for a Scatter chart.

Thank you.