即使您使用的是LogAxis,也可以指定整数刻度单位,如下面@ amaidment示例的变体所示.
/** @see https://stackoverflow.com/a/10353270/230513 */
private static void createFrame() {
XYSeries series = new XYSeries("Series");
for (int i = 0; i <= N; i++) {
series.add(i, Math.pow(2, i));
}
NumberAxis xAxis = new NumberAxis("X");
xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LogAxis yAxis = new LogAxis("Y");
yAxis.setBase(2);
yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
XYPlot plot = new XYPlot(new XYSeriesCollection(series),
xAxis, yAxis, new XYLineAndShapeRenderer(true, false));
JFreeChart chart = new JFreeChart(
"Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
JFrame frame = new JFrame("LogAxis Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Cha

这篇博客展示了如何在Java中使用LogAxis来创建对数坐标轴,并且详细说明了如何定制刻度标签,确保它们为整数单位。通过示例代码,展示了如何设置X轴和Y轴的刻度单位,以及如何设定Y轴的基数为2,以显示2的幂次方作为刻度值。
最低0.47元/天 解锁文章
9086

被折叠的 条评论
为什么被折叠?



