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
Formatting numbers with autoticks
RE: Formatting numbers with autoticks
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
// 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
RE: Formatting numbers with autoticks
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
// 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
RE: Formatting numbers with autoticks
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
dino
RE: Formatting numbers with autoticks
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.
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.
RE: Formatting numbers with autoticks
A simple flag would be suffice to indicate that the ticklabelformatter field should be used instead of the auto tick formatters. dino