Porblem with month in Jfreechart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
marouene_
Posts: 15
Joined: Fri Apr 01, 2011 3:32 pm
antibot: No, of course not.

Porblem with month in Jfreechart

Post by marouene_ » Tue Apr 19, 2011 3:50 pm

hello, i test

Code: Select all

ResultSet rs = con.execute("select month(date),avg(usr) from table group by month(date);");	
			while(rs.next()){
				
				int v1;
				
					v1 = rs.getInt("month(date)");
				
			 	double v2=rs.getFloat("avg(ftp)");
			 	Calendar cal = Calendar.getInstance();
			 	series.addOrUpdate( new Month(v1,cal.get(Calendar.YEAR)), v2);
			 	
			 }
			 rs.close();
but i took this error msg

Code: Select all

java.lang.IllegalArgumentException: Month outside valid range.
	at org.jfree.data.time.Month.<init>(Month.java:113)
i can't resolve the problem, tje values of month(date) are in (1,2,3,4,5,6,7,8,9,10,11,12)

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Porblem with month in Jfreechart

Post by paradoxoff » Tue Apr 19, 2011 8:22 pm

To summarize:
The IllegalArgumentException thrown in the contructor of Month indicates that the supplied argument is outside the range of 1-12.
On the other hand, you say that v1 which is the return value of month(date) is in (1,2,3,4,5,6,7,8,9,10,11,12).
w/o kowing the contents of the database, I tend to assume that your statement is not correct, and that you are picking up improper values.
As suggested in an other of your similar threads, I suggest to print some debug statements to the console to better see what is going on.

marouene_
Posts: 15
Joined: Fri Apr 01, 2011 3:32 pm
antibot: No, of course not.

Re: Porblem with month in Jfreechart

Post by marouene_ » Tue Apr 19, 2011 10:44 pm

this is my sql querry :

Code: Select all

select month(date),avg(ftp) from ftptable group by month(date);
this is my table :

Image
i take some changes in my code, this is the new version

Code: Select all

final TimeSeries series = new TimeSeries("", Month.class);
			ResultSet rs = con.execute("select month(date),avg(ftp) from ftptable where(year(date)=year(now())) group by month(date);");	
			
			while(rs.next()){
				
				int v1;
				
					v1 = rs.getInt("month(date)");
				
			 	double v2=rs.getFloat("avg(ftp)");
			 	Calendar cal = Calendar.getInstance();
			 	series.addOrUpdate( new Month(v1,cal.get(Calendar.YEAR)), v2);
			 	
			 }
			 rs.close();
			 DateAxis domain = new DateAxis("Time");
			 
		   	 	NumberAxis range = new NumberAxis("Débit en Ko/s");
		        final TimeSeriesCollection dataset = new TimeSeriesCollection();
		        dataset.addSeries(series);
		        dataset.setDomainIsPointsInTime(true);
		        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
		        XYPlot plot = new XYPlot(dataset, domain, range, renderer);
		        DateAxis axis = (DateAxis) plot.getDomainAxis();
				axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

		        plot.setBackgroundPaint(Color.lightGray);
		        plot.setDomainGridlinePaint(Color.white);
		        plot.setRangeGridlinePaint(Color.white);
		        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
		        range.setAutoRange(true);
		        range.setLowerMargin(0.0);
		        range.setUpperMargin(0.0);
		        range.setTickLabelsVisible(true);
		        range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
		        JFreeChart chart = new JFreeChart(plot);

		        XYItemRenderer r = plot.getRenderer();
		        if (r instanceof XYLineAndShapeRenderer) {
		            XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) r;
		            renderer1.setBaseShapesVisible(true);
		            renderer1.setBaseShapesFilled(true);
		        }
		        

		        chart.setTitle(new TextTitle("Evolution mensuelle du débit Ftp"));
		        
				
		        final ChartPanel chartPanel = new ChartPanel(chart);
		        chartPanel.setPreferredSize(new java.awt.Dimension(600, 300));
		        chartPanel.setMouseZoomable(true, false);	
		        
		        OutputStream out = response.getOutputStream(); 
		        ChartUtilities.writeChartAsPNG(out, chart, 700, 500);	
		   	 	request.setAttribute("image",out);
			 
			 
			 
			 
and this is the result of my graph
Image

i can't understand what's the problem

marouene_
Posts: 15
Joined: Fri Apr 01, 2011 3:32 pm
antibot: No, of course not.

Re: Porblem with month in Jfreechart

Post by marouene_ » Wed Apr 20, 2011 2:34 pm

No idea?

mkivinie
Posts: 51
Joined: Wed Jul 06, 2005 8:35 am

Re: Porblem with month in Jfreechart

Post by mkivinie » Thu Apr 21, 2011 2:11 pm

What are you trying to achieve?

Now you have summarized the database values into one datapoint per month. I am guessing that you have only date values for March and April in the database - hence the two datapoints in the graph.
Apparently this is not what you wanted, so please either re-think your logic or share with us what you would like to see.

Locked