Setting the "BaseUnit" of the categoryAxis in an Excel chart

Hello,

I can't find the procedure to set the "BaseUnit" of the categoryAxis in an Excel chart.

When I use the time-scale, the default "BaseUnit" is set to Months, but I want to change it to Days !

Can you help me with this ?

Thanks,

Goddeau Hendrik

Hi,

Thanks for considering Aspose.

Are you java version of Aspose.Cells. Could you give us the sample code here.

Thank you.

Hi,

In java version ,we don't support this feature. We will support it soon. Thanks for your patience.

Hi,

If you are using Java version, please try this fix.

See following codes:

CategoryAxis axis = chart.getCategoryAxis();
axis.setCategoryType(CategoryType.TIME_SCALE);
axis.setMajorUnitScale(TimeUnit.MONTHS);

Hello,

Thanks for adding this functionality. Can you please help me with the values I have to provide to the functions ?

TimeUnit.Months and Days - values ?

Time_scale ? --> 127 ?

Thanks !

Hendrik Goddeau
IT TW Aalst

Hi,

The constants members of TimeUnit reprent the unit of the category axis.

If you want to change the base unit, please use axis.setBaseUnitScale(TimeUnit.MONTHS);

if you want to change the major unit:

axis.setMajorUnit(1);
axis.setMajorUnitScale(TimeUnit.MONTHS);

if you want to change the minor unit:

axis.setMinorUnit(1);
axis.setMajorUnitScale(TimeUnit.DAYS);

Warren:

Hi,

The constants members of TimeUnit reprent the unit of the category axis.

If you want to change the base unit, please use axis.setBaseUnitScale(TimeUnit.MONTHS);

if you want to change the major unit:

axis.setMajorUnit(1);
axis.setMajorUnitScale(TimeUnit.MONTHS);

if you want to change the minor unit:

axis.setMinorUnit(1);
axis.setMajorUnitScale(TimeUnit.DAYS);

I have to pass pre-defined constant values to my procedures, but I don't know these values !!

See constant field values ...

Setting CategoryAxisType to "Timescale" doesn' t work anymore !!

Cause . . . . . : RPG procedure ACELLSETCA in program AAITMRMP1/ACELLSRV
received Java exception "java.lang.IllegalArgumentException: Invalid
category type." when calling method "setCategoryType" with signature "(I)V"
in class "com.aspose.cells.CategoryAxis".

Did this value change ????

Hi,

Yes, we have changed the values of CategoryType.

If you want to know the constant values of TimeUnit/CategoryType, please print them with console application. I list all the constant values.

public interface TimeUnit
{

/**
*
*/
public static final short DAYS = 0x00;
/**
*
*/
public static final short MONTHS = 0x01;
/**
*
*/
public static final short YERAS = 0x02;
}

public interface CategoryType
{

/**
*
*/
public static short AUTOMATIC_SCALE = 0x80;//0xEF;
/**
*
*/
public static short CATEGORY_SCALE = 0x0;//0x6F;
/**
*
*/
public static short TIME_SCALE = 0x10;//;0x7F;

}

Hi,

Can't you just give me the numeric values !?

Thanks

Hi,

class Name :TimeUnit

Constant number Name value

DAYS 0

MONTHS 1

YERAS 2

class Name :CategoryType

Constant number Name value

AUTOMATIC_SCALE 0x80

CATEGORY_SCALE 0

TIME_SCALE 0x10

0x80 = 128

0x10 = 16

Hello,

I’m using “Aspose.Cells for Java 1.9.1 Hot Fix”.

But I have a problem with the “CategoryType”:

CategoryAxis axis = chart.getCategoryAxis();
axis.setCategoryType(CategoryType.TIME_SCALE); 

==> java.lang.IllegalArgumentException: Invalid category type

I have tested the new values of CategoryType, but I have the same problem.

Can you help me?

Thanks

Nadège

Hello,

It should work when you specify a constant value = 16 for "Time_Scale".

Kind regards

Hi,

I have tried but I have got the same error !!

Hi,

Thanks for considering Aspose.

Could you post your template file with sample code to reproduce the issue.

Thank you.

Hi,

This is my code ( I have underline the line which poses problem).

protected void graphique2(com.aspose.cells.Workbook workbook, int min, int max) throws WriteException, IOException,ParseException,SQLException
{
com.aspose.cells.Font font;
com.aspose.cells.Font font1;

int i =2;
Worksheet sheet1 = workbook.getSheet(0);
Charts charts = sheet1.getCharts();


int index = charts.add(ChartType.LINE,i,6,(i+20),12);
Chart chart = charts.getChart(index);

PlotArea plot = chart.getPlotArea();
plot.setX(20);
plot.setY(20);
Line bd = plot.getBorder();
bd.setVisible(true);
plot.setWidth(3700);
plot.setHeight(3250);

Legend legend = chart.getLegend();
legend.setPosition(LegendPositionType.LEFT);
NSeries serieses = chart.getNSeries();
Title title = chart.getTitle();
ValueAxis valueaxis=chart.getValueAxis();
valueaxis.setCrossAt(100);


serieses.add("$R$"+ min , true);
serieses.setCategoryData("$U$"+min+":$U$"+max);

CategoryAxis axis = chart.getCategoryAxis();

axis.setCategoryType(16);//timescale
axis.setMajorUnitScale(new Short(“1”));//months

ASeries aseries= serieses.get(0);
aseries.setName(""+sheet1.getCell((min-2),17).getStringValue());
aseries.setValues("$V$"+ min +":$V$"+max+"");
aseries.setColorVaried(false);
Area area_a = aseries.getArea();
Line line = aseries.getBorder();
line.setWeight(1);
line.setColor(new Color(0,0,255));



serieses.add("$V$"+ min , true);

CategoryAxis cateAxis2 = chart.getCategoryAxis();
cateAxis2.setCrossAt(0);
com.aspose.cells.Font ftcat2= cateAxis2.getFont();
ftcat2.setSize(7);

ASeries aseries2= serieses.get(1);
aseries2.setName(""+sheet1.getCell((min-2),18).getStringValue());
aseries2.setValues("$W$"+ min +":$W$"+max+"");
aseries2.setColorVaried(false);
line = aseries2.getBorder();
line.setWeight(1);
line.setColor(new Color(0,128,0));




if (indice_2!=null)
{
serieses.add("$V$"+ min , true);
ASeries aseries3= serieses.get(2);
aseries3.setName(""+sheet1.getCell((min-2),19).getStringValue());
aseries3.setValues("$X$"+ min +":$X$"+max+"");
aseries3.setColorVaried(false);

}
/**/
DataLabels dl= aseries.getDataLabels();
com.aspose.cells.Font font_dl = dl.getFont();
font_dl.setSize(7);
dl.setValueShown(false);

title.setText(“Performances 1 an”);
font = title.getFont();
font.setBold(true);
font.setSize(8);

ChartArea chartArea = chart.getChartArea();
Line line2 = chartArea.getBorder();
line2.setVisible(false);


Line majorGridLines = valueaxis.getMajorGridLines();
majorGridLines.setVisible(false);


com.aspose.cells.Font ft= valueaxis.getFont();
ft.setSize(6);


chart.setLegendShown(true);
font1= legend.getFont();
font1.setSize(7);


Area area3 = legend.getArea();
area3.setForegroundColor(new com.aspose.cells.Color(192,192,192));
Line border1=legend.getBorder();
border1.setVisible(false);
}

Thanks

Nadège

Have you tried this : axis.setCategoryType(CategoryType.TIME_SCALE) ?

I tried with axis.setCategoryType(CategoryType.TIME_SCALE) and axis.setCategoryType(16)


I always have the same error: “java.lang.IllegalArgumentException: Invalid category type”

Hi,

We tried your codes. It works fine.

Please try the attached fix.

If it still does not work, please check the release version with CellsHelper.getReleaseVersion() method. It should be 1.9.1.2