I’m trying to draw a chart using JFreeChart on Java!
The data in which I’ll use in chart comes from DB.
So I have a table of pannes with many types, I count then the number of pannes for each one and use the method of JFreeChart to add them to the dataSet.
My problem is I didn’t get any thing in output.
Here’s the a bit of code!
for (int i =0 ; i<typesPannes.length ; i++)
{
ResultSet res = st.executeQuery(req+" and typeDerang = '"+typesPannes[i]+"'");
System.out.println(req+" and typeDerang = '"+typesPannes[i]+"'");
int count=0;
while (res.next()) { count++ ; }
System.out.println(count) ;
dataset.setValue(count, " " , typesPannes[i]);
}
JFreeChart chart = ChartFactory.createBarChart ("BarChart using JFreeChart","row", "col", dataset,
PlotOrientation.VERTICAL, false,true, false);
chart.setBackgroundPaint(Color.yellow);
chart.getTitle().setPaint(Color.blue);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.red);
ChartPanel ch1=new ChartPanel(chart);
panel.add(ch1);
is there any problem with the dataSet or …. Help please!
dataset.setValue(count, ” ” , typesPannes[i]);
Thanks for help !!!
Try replacing by:
As you have only one category but multiple series.
Edit after seeing the screenshot:
The chart comes up fine for me when I replace panel.add(ch1); with new JFrame containing the chart.
So you need to check whether the panel is already added to your main frame and whether it is not getting repainted etc. You can try resizing the main frame. You can also try to add a simple JLabel and check that it is displayed in your frame correctly before adding the chart.