XYPlot の dataArea を取得しようとしていますが、配置したグラフ パネルはそれを記録していないようです。要求するたびに、高さ、幅、x、y の値が常に 0 になります。
private JPanel createChartPanel()
{
JPanel chartAreaPanel = new JPanel();
JFreeChart originalDataChart = createOriginalDataChart();
ChartPanel originalDataPanel = new ChartPanel(originalDataChart);
drawDataDirections(originalDataChart, originalDataPanel);
//This is where I need originalDataPanel's ChartRenderingInfo,
//but all of the relevant fields in it are zero. Why?
originalDataPanel.setPreferredSize(new Dimension(960, 500));
chartAreaPanel.setLayout(new GridBagLayout());
chartAreaPanel.add(originalDataPanel);
JPanel centerPanel = new JPanel();
JPanel chartPanel = new JPanel(new BorderLayout());
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
TitledBorder chartBorder = BorderFactory.createTitledBorder(etchedBorder, "Timeseries Chart");
chartBorder.setTitlePosition(TitledBorder.TOP);
chartPanel.setBorder(chartBorder);
centerPanel.add(chartAreaPanel);
chartPanel.add(centerPanel, BorderLayout.EAST);
return chartPanel;
}
以下は drawDataDirections() です
private void drawDataDirections(JFreeChart jfc, ChartPanel cp)
{
XYPlot original = ((XYPlot) ((CombinedDomainXYPlot) jfc.getXYPlot()).getSubplots().get(0));
XYDataset data = original.getDataset(0);
Rectangle2D dataArea = cp.getChartRenderingInfo().getPlotInfo().getDataArea();
ValueAxis domAxis = original.getDomainAxis();
ValueAxis rngAxis = original.getRangeAxis();
float[] xCoords = new float[data.getItemCount(0)];
float[] yCoords = new float[data.getItemCount(0)];
double[] angles = new double[data.getItemCount(0)];
//These three values need to be set in advance, as they are never reached.
xCoords[0] = (float) domAxis.valueToJava2D(data.getXValue(0, 0), dataArea, original.getDomainAxisEdge());
yCoords[0] = (float) rngAxis.valueToJava2D(data.getYValue(0, 0), dataArea, original.getRangeAxisEdge());
angles[angles.length - 1] = 0.0;
for (int i = 1;i < data.getItemCount(0);i++)
{
xCoords[i] = (float) domAxis.valueToJava2D(data.getXValue(0, i), dataArea, original.getDomainAxisEdge());
yCoords[i] = (float) rngAxis.valueToJava2D(data.getYValue(0, i), dataArea, original.getRangeAxisEdge());
angles[i] = Math.atan2(yCoords[i] - yCoords[i - 1], xCoords[i] - xCoords[i - 1]);
}
((XYLineAndShapeRendererExtended) original.getRenderer(0)).setAngles(angles);
((XYLineAndShapeRendererExtended) original.getRenderer(0)).setCoords(xCoords, yCoords);
//Finally, start drawing the shapes.
((XYLineAndShapeRendererExtended) original.getRenderer(0)).setSeriesShapesVisible(0,true);
}