numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //关键就是这句

numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //关键就是这句

public static void createLineChart(double[] data) { XYSeries series = new XYSeries("Data"); for (int i = 0; i < data.length; i++) { series.add(i+1, data[i]/10000); } XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart( "Best Time vs. Generation", "Generation", "Best Time", dataset, PlotOrientation.VERTICAL, true, true, false ); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setTickUnit(new NumberTickUnit(100)); xAxis.setTickMarkInsideLength(5.0f); xAxis.setTickMarkOutsideLength(0.0f); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setTickUnit(new NumberTickUnit(0.01)); yAxis.setTickMarkInsideLength(5.0f); yAxis.setTickMarkOutsideLength(0.0f); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(500, 500)); JFrame frame = new JFrame("Plot"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(chartPanel); frame.pack(); frame.setVisible(true); } 如何将纵轴变成可以自适应数据大小的
最新发布
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值