3

I have a StackedXYAreaChart that looks like the following:

enter image description here

How do I format the Y-axis units so that they are evenly spaced out and are displayed at certain intervals? For example, instead of displaying units in increments of 1 (e.g. 0, 1, 2, 3, ... 100), I want to display units in increments of 10 or 25 (e.g., 0, 25, 50, 75, 100). Thanks!

BJ Dela Cruz
  • 5,194
  • 13
  • 51
  • 84

3 Answers3

4

I found a solution to my own question. I'm using a CustomTickUnit that formats numbers and adds units to the suffix, e.g. 1000000 becomes 1 GB.

I set up my tick units with the following code, which spaced them out evenly and formatted them appropriately so that they are very readable:

public void setupRangeAxis(NumberAxis rangeAxis) {
  final TickUnits standardUnits = new TickUnits();
  standardUnits.add(new CustomTickUnit(1));
  standardUnits.add(new CustomTickUnit(10));
  standardUnits.add(new CustomTickUnit(100));
  standardUnits.add(new CustomTickUnit(1000)); // Kilo
  standardUnits.add(new CustomTickUnit(10000));
  standardUnits.add(new CustomTickUnit(100000));
  standardUnits.add(new CustomTickUnit(1000000)); // Mega
  standardUnits.add(new CustomTickUnit(10000000));
  standardUnits.add(new CustomTickUnit(100000000));
  standardUnits.add(new CustomTickUnit(1000000000)); // Giga
  standardUnits.add(new CustomTickUnit(10000000000L));
  standardUnits.add(new CustomTickUnit(100000000000L));
  standardUnits.add(new CustomTickUnit(1000000000000L)); // Tera
  standardUnits.add(new CustomTickUnit(10000000000000L));
  standardUnits.add(new CustomTickUnit(100000000000000L));
  standardUnits.add(new CustomTickUnit(1000000000000000L)); // Peta
  standardUnits.add(new CustomTickUnit(10000000000000000L));
  standardUnits.add(new CustomTickUnit(100000000000000000L));
  standardUnits.add(new CustomTickUnit(1000000000000000000L)); // Exa
  rangeAxis.setStandardTickUnits(standardUnits);
}
BJ Dela Cruz
  • 5,194
  • 13
  • 51
  • 84
2
CategoryPlot plot = chart.getCategoryPlot();

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

rangeAxis.setTickUnit(new NumberTickUnit(300));
Steve Lillis
  • 3,263
  • 5
  • 22
  • 41
thulasi
  • 21
  • 1
1

Assuming a NumberAxis, set the tick unit to 25. There's a related example here.

axis.setTickUnit(new NumberTickUnit(25));
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045