Problems with formatting tick labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Alexander Bjerke

Problems with formatting tick labels

Post by Alexander Bjerke » Mon Mar 19, 2001 3:26 pm

Hi

No matter what I try, I can't get the formatting of the tick labels in my TimeSeries-plot to work. I use a HorizontalDateAxis as the x-axis and try to apply a pattern to the tickLabelFormatter, but the dates are formatted as "14-Sep-2000" regardless of what pattern I choose. Here is a part of my code (the comments and variable names are in norwegian). Anyone know what I should do to get it right?

Note: The createTimeSeriesChartWithDetails-method is similar to the createTimeSeriesChart-method

****

JFreeChart graf = JFreeChart.createTimeSeriesChartWithDetails( fondXYData, tittelTekst, tittelFont );

graf.setAntiAlias( antialiasGraf );
graf.setChartBackgroundPaint( bgrFargeGraf );
graf.setSeriesPaint( fargeGrafer );

Plot kursPlot = graf.getPlot();

HorizontalDateAxis xAkse = ( HorizontalDateAxis )kursPlot.getAxis(Plot.HORIZONTAL_AXIS);
xAkse.getTickLabelFormatter().applyPattern( "dd.MM.yyyy" );
xAkse.setLabelFont( xAkseFont );
xAkse.setLabel( xAkseTekst );
xAkse.setLabelInsets( new Insets( 10, 2, 2, 2 ) );

xAkse.setAutoTickValue( true );
xAkse.setMinimumDate( new Date( 100, 9, 15 ) );
xAkse.setMaximumDate( new Date( 100, 10, 2 ) );

xAkse.setVerticalTickLabels( true );

xAkse.setGridPaint( gridFarge );
xAkse.setGridStroke( gridStrek );

David Gilbert

RE: Problems with formatting tick labels

Post by David Gilbert » Mon Mar 19, 2001 9:21 pm

Hi Alexander,

When the axis calculates the tick values automatically, it also grabs a tick format and applies it right over top of the one you have set. Take a look in the DateAxis.java file at the standardTickFormats array (down at the bottom of the source file) - you can modify this to give the format you require, just make sure the number of items is equal to the other two arrays defined in there (standardTickUnitMagnitudes and standardTickUnits).

The setting of the format happens in the calculateAutoTickUnits() method in HorizontalDateAxis.java.

Regards,

DG.

Locked