JFreeChart and Y-axis Units

后端 未结 3 1641
梦如初夏
梦如初夏 2021-01-14 11:00

I have a StackedXYAreaChart that looks like the following:

\"enter

How do I fo

相关标签:
3条回答
  • 2021-01-14 11:38
    CategoryPlot plot = chart.getCategoryPlot();
    
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    
    rangeAxis.setTickUnit(new NumberTickUnit(300));
    
    0 讨论(0)
  • 2021-01-14 11:39

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

    axis.setTickUnit(new NumberTickUnit(25));
    
    0 讨论(0)
  • 2021-01-14 11:51

    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);
    }
    
    0 讨论(0)
提交回复
热议问题