java 刻度坐标轴_java – 对数轴标签/刻度定制

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

即使您使用的是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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值