In the following code, I want to reduce the font size of the y-axis and x-axis values.
I searched and found these code:
suppose you want to reduce the font size of number axis use the following code:
Font nwfont=new Font("Arial",0,7);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setTickLabelFont(nwfont);
suppose you want to reduce the font size of CategoryAxis use the following code:
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelFont(nwfont);
but unfortunately, the size of the axes did not decrease. Did I do something wrong?
this sample code:
public class NegativeExpPlot {
public static void main(String[] args) throws IOException {
EventQueue.invokeLater(new NegativeExpPlot()::display);
}
private void display() {
int nData = 100;
Random r = new Random(nData);
XYSeries ds1 = new XYSeries("rand");
for (int i = 0; i < nData; i++) {
ds1.add(r.nextDouble(), r.nextDouble() / 1000);
}
for (int i = 0; i < nData; i++) {
ds1.add(r.nextDouble(), r.nextDouble() * 1000);
}
LogAxis logAxis = new LogAxis("log");
XYPlot p = new XYPlot(new XYSeriesCollection(ds1), new NumberAxis(),
logAxis, new XYLineAndShapeRenderer());
logAxis.setNumberFormatOverride(new DecimalFormat("0.0E0"));
Font nwfont=new Font("Arial",0,1);
logAxis.setTickLabelFont(nwfont);
JFreeChart chart = new JFreeChart(p);
JFrame f = new JFrame("Log Axis");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new ChartPanel(chart));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis();
rangeAxis.setTickLabelFont(nwfont);
}
}