When I click on a section of my piechart, I would like to see under first chart another chart (line chart). Now I generated another panel chart, but I lost first panel, because the second chart paint on first panel and second paint a first chart, but second has bad dimension; see image.
How i can adjust my problem?
JFreeChart chart = ChartFactory.createPieChart("Pratiche complessive",
dataset, true, true, false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(560, 370));
PiePlot plot = (PiePlot) chart.getPlot();
PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator(
"{1} pratica/che");
plot.setLabelFont(new Font("Courier New", Font.BOLD, 10));
plot.setLabelLinkPaint(Color.BLACK);
plot.setLabelLinkStroke(new BasicStroke(1.0f));
plot.setLabelOutlineStroke(null);
plot.setLabelPaint(Color.BLUE);
plot.setLabelBackgroundPaint(null);
plot.setLabelGenerator(gen);
chart.setBackgroundPaint(Color.orange);
chartPanel.addChartMouseListener(this);
this.setContentPane(chartPanel);
}
public void chartMouseClicked(ChartMouseEvent event) {
ChartEntity entity = event.getEntity();
String sezione = "";
sezione = entity.toString().substring(17);
sezione = sezione.replace(")", "");
System.out.println(sezione);
// PieSection: 0, 0(ARCHIVIATO)===>ARCHIVIATO V
if (entity != null) {
try {
String query = query;
String numero_pratiche = "";
String nome_stato = "";
String data_modifica;
stmt = conn.prepareStatement(query);
rs = stmt.executeQuery();
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
while (rs.next()) {
dataset
}
// System.out.println(entity.toString());
JFreeChart lineChart = ChartFactory.createLineChart("Pratiche", "Data", "Pratiche", dataset, PlotOrientation.VERTICAL,true, true, false);
ChartPanel pannello_dettaglio = new ChartPanel(lineChart);
pannello_dettaglio.setPreferredSize(new java.awt.Dimension(560,367));
this.setContentPane(pannello_dettaglio);
JfreeChart dettaglio = new JfreeChart("Dettaglio");
pannello_dettaglio.setSize(560, 367);
RefineryUtilities.centerFrameOnScreen(dettaglio);
dettaglio.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
//first panel(piechart)
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
JfreeChart demo = new JfreeChart("Pratiche complessive");
demo.setSize(560, 367);
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
this is my first chart pie:
This is my final result:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…