嗨,我有一个包含产品的数据库,并且有不同类别的特征,我设法制作了一个图,其中包含一个在不同时间每个类别的一个产品,如图
所示。但是我想对我拥有的所有产品执行此操作,我希望它们都处于同一图形中,所以任何人都可以执行或不执行此操作,我该怎么做? 这是我使用的代码
void initcoure(String prod,String semaine,String post) {
try {
CategoryDataset das=createDataset(prod,semaine,post);
JFreeChart createChart = createChart(das,listeproduit2.getSelectedItem(),md1.getColumnName(1));
cPanel = new ChartPanel(createChart);
cPanel.setSize(Chartpanel.getWidth(),200);
cPanel.setVisible(true);
Chartpanel.setLayout(new BorderLayout());
Chartpanel.add(cPanel,BorderLayout.SOUTH);
Chartpanel.validate();
Chartpanel.repaint();
} catch (SQLException ex) {
Logger.getLogger(Courbes.class.getName()).log(Level.SEVERE, null, ex);
}
}
public CategoryDataset createDataset(String prod,String semaine,String post){
connection();
DefaultCategoryDataset datasetessai=new DefaultCategoryDataset();
ResultSet rst;
try {
if (inposte==true)
{ rst= DataBase.selection("select `Nom produit`"+semaine+" FROM `allin` WHERE `poste`= '"+prod+" '"+post+" order by `SFIN OU CIE` ");
}
else
{ rst= DataBase.selection("select `poste`"+semaine+" FROM `allin` WHERE `Nom produit`= '"+prod+" '"+post+" order by `SFIN OU CIE` ");}
// + "WHERE `Nom produit`= '"+prod+" '"+post+" order by `SFIN OU CIE` ");
md1 = rst.getMetaData();
int sum= md1.getColumnCount();
while(rst.next())
{
try {
for (int i=2; i<=sum;i++)
datasetessai.addValue(rst.getFloat(i),rst.getString(1) ,md1.getColumnName(i) );
} catch (SQLException ex) {
Logger.getLogger(Courbes.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (SQLException ex) {
Logger.getLogger(Courbes.class.getName()).log(Level.SEVERE, null, ex);
}
return datasetessai;
}
public JFreeChart createChart(CategoryDataset Dataset,String prod,String X)
{ JFreeChart chart= ChartFactory.createBarChart(prod,X, "Pourentage ", Dataset,PlotOrientation.VERTICAL,true,true,false);
plot= (CategoryPlot) chart.getPlot();
chart.setBorderVisible(true);
chart.getCategoryPlot().setBackgroundPaint(new Color(54, 63, 73));
return chart; }