1

I have a chart with a logarithmic yAxis like this one: logarithmic chart

As we can see, the yAxis have exponential ticks (I setted it that way with yAxis.setExpTickLabelsFlag(true);). Here is the same chart with a linear axis (the one by default when creating a xylineChart):

linear chart

Unfortunately, my values on the yAxis can't be formatted with exponential ticks because it is not a LogarithmicAxis. How can I force it to?

pioupiou1211
  • 353
  • 4
  • 16
  • `NumberAxis::setNumberFormatOverride`? – trashgod Apr 11 '17 at 20:48
  • @trashgod it seems to be the way to achieve it thank you. I used `yAxis.setNumberFormatOverride(new DecimalFormat("0.######E0"));` but I want to set the exponential as a lower case like `1e5`. Replacing the `E` by `e` give me an illegal argument error. By the way, don't hesitate to post is as an answer so that I can mark it as the solution. – pioupiou1211 Apr 12 '17 at 07:17
  • @trashgod either this or make the ticks of the `logarithmicAxis` to upper case. I want something symetric. – pioupiou1211 Apr 12 '17 at 07:38

1 Answers1

1

As shown here, you can invoke setNumberFormatOverride() to set the desired DecimalFormat. You can invoke the setExponentSeparator() method of DecimalFormatSymbols to set the desired exponent separator.

DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setExponentSeparator("e");
DecimalFormat format = new DecimalFormat("0.######E0", symbols);
yAxis.setNumberFormatOverride(format);

Alternatively, you should be able to modify the numberFormatterObj of LogarithmicAxis in a custom implementation of setupNumberFmtObj(), seen here, but I haven't tried it.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045