如何访问XYSeries
并XYPlot
放置在JFrame
?当然,我可以使用变量名series
and plot
,但我的问题是指访问这些组件的函数式方式,即f.getContentPane()
……这在函数返回时很有用JFrame
。
JFrame f = new JFrame(title);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BorderLayout(0, 5));
XYSeries series = new XYSeries("");
XYDataset data = createDataset(series,0,indf,oldpop);
JFreeChart chart = ChartFactory.createScatterPlot(title, xtitle, ytitle, data, PlotOrientation.VERTICAL, false, true, false);
XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer =
(XYLineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true); plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
ChartPanel chartPanel = new ChartPanel(chart);
f.add(chartPanel, BorderLayout.CENTER);
chartPanel.setMouseWheelEnabled(true);
chartPanel.setHorizontalAxisTrace(true);
chartPanel.setVerticalAxisTrace(true);
JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
f.add(panel, BorderLayout.SOUTH);