Formatting numbers with autoticks

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

Formatting numbers with autoticks

Post by Dino Valente » Fri May 18, 2001 8:46 pm

How can one set the format of numbers (eg for the vertical number axis) to be constant when auto tick is true?

It seems that the auto tick values retrieves the corresponding formatter in a static array (which is fine for standard situations). However, i want to display dollar values and thus I want to display everything to 2 decimal places. Is there something I'm missing or do I have to hack the source code?

dino

Daniel Serodio

RE: Formatting numbers with autoticks

Post by Daniel Serodio » Mon May 21, 2001 6:14 pm

You can set the format of numbers, here is a small example:

// Create your chart
JFreeChart chart = JFreeChart.createTimeSeriesChart(dataSource);

// Now set the axis' format
Plot plot = chart.getPlot();
NumberAxis vAxis = (NumberAxis)plot.getAxis(Plot.VERTICAL_AXIS);
DecimalFormat vAxisFormat = vAxis.getTickLabelFormatter();
vAxisFormat.applyPattern(".##");

Hope that works for you. I'm able to set the horizontal axis' (DateAxis) format, but not the vertical one.

[]'s
Daniel Serodio

Daniel Serodio

RE: Formatting numbers with autoticks

Post by Daniel Serodio » Mon May 21, 2001 6:29 pm

You can set the format of numbers, here is a small example:

// Create your chart
JFreeChart chart = JFreeChart.createTimeSeriesChart(dataSource);

// Now set the axis' format
Plot plot = chart.getPlot();
NumberAxis vAxis = (NumberAxis)plot.getAxis(Plot.VERTICAL_AXIS);
DecimalFormat vAxisFormat = vAxis.getTickLabelFormatter();
vAxisFormat.applyPattern(".##");

Hope that works for you. I'm able to set the horizontal axis' (DateAxis) format, but not the vertical one.

[]'s
Daniel Serodio

Dino Valente

RE: Formatting numbers with autoticks

Post by Dino Valente » Mon May 21, 2001 11:14 pm

This doesn't work since the autotick format overrides the ticklabelformatter (I actually expected it to work as you had described it). It seems (at least to me at) that the tick formatting is somewhat confusing and inconsistent.

dino

David Gilbert

RE: Formatting numbers with autoticks

Post by David Gilbert » Tue May 22, 2001 9:51 pm

Hi Dino,

Hack the source code for now - put whatever format you require in the autoTickFormats array at the bottom of the NumberAxis.java file, making sure that there is one format for each item in the autoTickValues array (also in NumberAxis.java).

I'll think about what modifications to make so that it can be done more easily in future...

Regards,

DG.

Dino Valente

RE: Formatting numbers with autoticks

Post by Dino Valente » Tue May 22, 2001 11:19 pm

A simple flag would be suffice to indicate that the ticklabelformatter field should be used instead of the auto tick formatters. dino

Locked