Logarithmic Axis Labels/Ticks Customization

后端 未结 3 443
忘了有多久
忘了有多久 2020-11-29 11:13

I am using the JFreeChart API to generate some chart in my Java application. In one of my charts, I try to use the LogAxis object to make my y-axis

3条回答
  •  一个人的身影
    2020-11-29 12:08

    I think what you need is logAxis.setNumberFormatOverride(NumberFormat format);

    EDIT: Since further help is needed... try this:

    logAxis.setBase(10);
    LogFormat format = new LogFormat(logAxis.getBase(), "", "", true);
    logAxis.setNumberFormatOverride(format);
    

    Here's a whole method that can be used to play with...:

      public static void main(String[] args) {
        XYSeries series = new XYSeries("");
        series.add(1, 10);
        series.add(2, 100);
        series.add(3, 1000);
        series.add(4, 10000);
        series.add(5, 100000);
        series.add(6, 1000000);
    
    //    NumberAxis yAxis = new NumberAxis("");
        LogAxis yAxis = new LogAxis("");
        yAxis.setBase(10);
        LogFormat format = new LogFormat(yAxis.getBase(), "", "", true);
        yAxis.setNumberFormatOverride(format);
        XYPlot plot = new XYPlot(
          new XYSeriesCollection(series),
          new NumberAxis(""),
          yAxis,
          new XYLineAndShapeRenderer(true, false));
        JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    
        JFrame frame = new JFrame("LogAxis Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(new ChartPanel(chart));
        frame.pack();
        frame.setVisible(true);
      }
    

提交回复
热议问题