How to put the Label of my TickLabels in exponential format

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
cirilio
Posts: 3
Joined: Sun May 02, 2010 6:09 pm
antibot: No, of course not.

How to put the Label of my TickLabels in exponential format

Post by cirilio » Sun May 02, 2010 6:16 pm

Hello everybody,

Is there anybody who know , how should I do to put my axis' TickLabels in Exponantial Format?

200000 =>2E5

100000 =>1E5

10000 =>1E4

cirilio
Posts: 3
Joined: Sun May 02, 2010 6:09 pm
antibot: No, of course not.

Re: How to put the Label of my TickLabels in exponential format

Post by cirilio » Sun May 02, 2010 6:22 pm

Actually I've found a method to format a double in exponantial:

NumberFormat formatter = new DecimalFormat("0E0");
String s = formatter.format(-1234.567); // -1E3


However the method add(x,y) of XYSeries doesn't accept String as parameters!!!

jsnel
Posts: 19
Joined: Thu Apr 19, 2007 12:00 pm

Re: How to put the Label of my TickLabels in exponential format

Post by jsnel » Sun May 02, 2010 7:38 pm

You should not be formatting the number before you add them to the chart, you Axis class should be formatting them. If you do not like the default formatting you can override the default numberformat by callling the axis setNUmberFormatOverride method, like this:

Code: Select all

NumberAxis xAxis = new NumberAxis();
xAxis.setNumberFormatOverride(new DecimalFormat("0E0"));
Of course you can use whatever Axis you prefer, or even write you own :)
If you used the ChartFactory then probably you have a JFreeChart chart variable, in that case you can do:

Code: Select all

//JFreeChart chart
XYPlot plot = (XYPlot) chart.getPlot();
NumberAxis xAxis = new NumberAxis();
xAxis.setNumberFormatOverride(new DecimalFormat("0E0"));
plot.setDomainAxis(xAxis);
Creator of Glotaran, a software program developed for global and target analysis of time-resolved spectroscopy and microscopy data. Big fan of JFreeChart.

cirilio
Posts: 3
Joined: Sun May 02, 2010 6:09 pm
antibot: No, of course not.

Re: How to put the Label of my TickLabels in exponential format

Post by cirilio » Sun May 02, 2010 8:05 pm

Thank you for answering!!!

That' s exactly what i needed!

Locked