ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Gap between marker and label's edge
Posted by Alexandre on Oct-10-2011 16:11
Attachments:
Hi,

I want to make a graph with multiple x-axis and markers for years.
I based this on to my post on Friday for markeurs and another post on this forum for the x-axis.

My present problem (illustrated by the attached picture) is: there is a gap between the markeur and the edge of the label.
Would you have any idea why and how to solve the problem ?

The code is below. It's actually a test (data are fixe).

Thanking you in advance,
Regards,
Alexandre.


/******* The Code *******/
Date[] dates = buildXTickValues(new GregorianCalendar(2003,Calendar.JANUARY, 1).getTime(), new GregorianCalendar().getTime()) ;
double[] data0 = Randomizer.random(dates.length, 100, 75, 225, 15) ;
double[] data1 = Randomizer.random(dates.length, 100, 75, 225, 15) ;
double[] data2 = Randomizer.random(dates.length, 100, 75, 225, 15) ;

// ### Definition de l'image ###
// - longueur, hauteur, fond, bordure, effet de la bordure
XYChart c = new XYChart(1000, 400, 0xffffff, Chart.Transparent, 0);
// - si bordure, permet d'avoir les coins arrondits
//c.setRoundedFrame();

// ### La zone de dessin ###
// - on construit une zone (x, y, longueur, hauteur, couleur du fond, couleur alt. du fond, couleur de la bordure, couleur lignes H de la grille, couleur lignes V de la grille)
c.setPlotArea(55, 40, 850, 195, Chart.Transparent, Chart.Transparent, Chart.Transparent, 0xcccccc, Chart.Transparent);

// ### Gestion du titre du graphique ###
// - titre, police, taille
c.addTitle("Variation de la performance", "Times New Roman Bold Italic", 15) ;

// ### Gestion de la l?gende ###
// - on d?fini la l?gende (x, y, true=V|false=H, famille, taille)
LegendBox legendBox = c.addLegend(50, 350, false, "Arial Bold", 9);
// - couleur du fond et de la bordure
legendBox.setBackground(Chart.Transparent, Chart.Transparent);
// - alignement
legendBox.setAlignment(Chart.BottomCenter);
// - positionnement de la l?gende au centre de la ligne
legendBox.setPos(c.getPlotArea().getLeftX() + (c.getPlotArea().getWidth() - legendBox.getWidth()) / 2, legendBox.getTopY());

// ### Gestion des libelles de l'axe des abscisses ###
// - gestion de la num?rotation des ticks : date de d?but, date de fin, incr?ment des 'ticks majeurs' (avec libell?), incr?ment des ticks mineurs (sans libell?) ; ? noter que 1 mois=30*86400
c.xAxis().setDateScale(new GregorianCalendar(2003,Calendar.JANUARY, 1).getTime(), new GregorianCalendar(2011,Calendar.DECEMBER, 1).getTime(), 1*30*86400, 1*30*86400) ;
c.xAxis().setColors(Chart.Transparent, Chart.Transparent);

//Ajout des axis
Axis a = c.addAxis(Chart.Bottom, 0);

// 1ere ligne : les mois
String[] axisLabelsM = new String[(2011 - 2003 + 1) * 12];
String[] monthNames = {"J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"};
for (int i = 0; i < axisLabelsM.length; i+=monthNames.length) { System.arraycopy(monthNames, 0, axisLabelsM, i, 12); } // compute label
a.setLabels(axisLabelsM);
CDMLTable t = a.makeLabelTable();

// ligne suivante : les trimestres
t.insertRow(0);
String[] trimestreNames = {"T1", "T2", "T3", "T4"};
for (int i = 0; i < axisLabelsM.length; i += 3) {
t.setCell(i, 0, 3, 1, trimestreNames[(i/3)%4]);
}

// ligne suivante : les semestres
t.insertRow(0);
for (int i = 0; i < axisLabelsM.length; i += 6) {
t.setCell(i, 0, 6, 1, ((i/6)%2 == 0) ? "S1" : "S2");
}

// ligne suivante : les annees
t.insertRow(0);
for (int i = 0; i < axisLabelsM.length; i += 12)
    t.setCell(i, 0, 12, 1, "" + (2003 + i / 12));


// ### Gestion des libelles de l'axe des ordonnees ###
// - titre de l'axe
c.yAxis().setTitle("(M d'?)");


// ### Ajout des series ###
// Et de une
AreaLayer layer0 = c.addAreaLayer(data0, 0xff5233, "Fonds");
layer0.setBorderColor(Chart.Transparent) ;
layer0.setXData(dates);
layer0.setLineWidth(1);

// Et de deux
LineLayer layer1 = c.addLineLayer2();
layer1.addDataSet(data1, 0xffd508, "SBF 120");
layer1.setXData2(new GregorianCalendar(2006,Calendar.JUNE,1).getTime(), new GregorianCalendar().getTime());
layer1.setLineWidth(2);
layer1.moveFront() ;

// Une petite derni?re
LineLayer layer2 = c.addLineLayer2();
layer2.addDataSet(data2, 0x06f002, "SBF 120 div. r?invest.");
layer2.setXData2(dates[0], dates[dates.length-1]);
layer2.setLineWidth(2);
layer2.moveFront() ;

// Les markeurs
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2003,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2004,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2005,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2006,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2007,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2008,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2009,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
c.xAxis().addMark(Chart.CTime(new GregorianCalendar(2010,Calendar.DECEMBER,31).getTime()), 0xaaaaaa, null).setLineWidth(1) ;
graph.png

  Re: Gap between marker and label's edge
Posted by Peter Kwan on Oct-10-2011 22:18
Hi Alexandre,

In your axis labels, you have 7 years of labels (total duration is 112 months). However, in your date scale, the duration is only 6 years 11 months. (You are uisng Jan 1, 2003 to Dec 1, 2011.)

I suggest you change the date scale to Jan 1, 2003 00:00:00 to Jan 1, 2012 00:00:00 instead. This would be exactly 7 years, and will match with your labels.

If you do not want to use Jan 1, 2012 00:00:00, you may use Dec 31, 2011 23:59:59. There is then a 1 second difference, but I think for your chart, this small difference is not visible.

Hope this can help.

Regards
Peter Kwan

  Re: Gap between marker and label's edge
Posted by Alexandre on Oct-10-2011 23:20
Hi Peter,

Excellent remark.
Excellent solution.
And all, as usual, promptly.

Thank you very much,
Best regards,
Alexandre.