gpt4 book ai didi

java - JFreeChart 格式 Y 轴以显示 Power 中的值

转载 作者:太空宇宙 更新时间:2023-11-04 06:58:10 26 4
gpt4 key购买 nike

如何设置 y 轴格式以将值显示为 5*10^5、1*10^6、2*10^6...而不是 500,000、1,000,000、2,000,000...并且可被 5 或 10 整除?

enter image description here

最佳答案

一个LogAxis使用默认的刻度单位似乎可以工作。此相关example使用整数刻度单位。

image

import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
* @see https://stackoverflow.com/a/22450677/230513
* @see https://stackoverflow.com/a/10353270/230513
*/
public class Test {

private static final int N = 7;

private void display() {
XYSeries series = new XYSeries("Series");
for (int i = 0; i <= N; i++) {
series.add(i, Math.pow(10, i));
}
NumberAxis xAxis = new NumberAxis("X");
xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LogAxis yAxis = new LogAxis("Y");
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 f = new JFrame("Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new ChartPanel(chart) {

@Override
public Dimension getPreferredSize() {
return new Dimension(480, 240);
}
});
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
new Test().display();
}
});
}
}

关于java - JFreeChart 格式 Y 轴以显示 Power 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22447540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com