How to get an access to the XYSeries
and XYPlot
placed on JFrame
? Of course, I can use the variable names series
and plot
, but my question refers to the functional way to access these components, ie f.getContentPane()
... This is useful when the function returns 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);
ChartPanel
is JComponent
which renders JFreeChart
; both XYSeries
and XYPlot
are components, these objects used by JFreeChart
. Since they're not components, you can't access them by traversing component hierarchy, you have to get them from ChartPanel
and JFreeChart
.
Find ChartPanel
in the component hierarchy, use getChart()
to get JFreeChart
object, and then get the objects you want from it, just like you do in the code above:
XYPlot plot = chart.getXYPlot();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.