data not showing in timeseries chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
annac
Posts: 24
Joined: Mon Oct 01, 2007 7:56 pm
Location: Canada

data not showing in timeseries chart

Post by annac » Thu Oct 25, 2007 4:58 pm

hi,

I have a chart in an applet which is obtaining data from our database. I am querying a time period of 7 days, 5 of which have data. If I let the chart auto range the data then it plots the 5 days along the x axis and the chart looks normal. However, if I specifically set the maximum and minimum dates for the x axis (the 7 days that were queried) then the data is not plotted and I end up with an empty chart.

Here is the code:

Code: Select all

		TimeSeries ts = new TimeSeries(info.getInstrumentName());
		
		while(secondIterator.hasNext()) {
			
			int second = ((Integer) secondIterator.next()).intValue();
			int minute = ((Integer) minuteIterator.next()).intValue();
			int hour = ((Integer) hourIterator.next()).intValue();
			int day = ((Integer) dayIterator.next()).intValue();
			int month = ((Integer) monthIterator.next()).intValue();
			int year = ((Integer) yearIterator.next()).intValue();
			
			Second aTime = new Second(second,minute,hour,day,month,year);
			Double aValue = (Double) valueIterator.next();
			
			if(aTime != null) {
				ts.addOrUpdate(aTime, aValue);
			}
			
		}
		
		TimeSeriesCollection dataset = new TimeSeriesCollection();
		
		dataset.addSeries(ts);
		
		JFreeChart chart = ChartFactory.createTimeSeriesChart(
				"", 
				"Time [UTC]", 
				info.getSensorTypeName() + " [" + info.getSensorUofM() + "]", // y-axis label
				dataset, 
				false, 
				true, 
				false);
	
		// chart title
		TextTitle title = new TextTitle("Instrument: " + info.getInstrumentName());
		title.setHorizontalAlignment(HorizontalAlignment.LEFT);
		chart.setTitle(title);

		chart.setBackgroundPaint(Color.white);
		XYPlot plot = (XYPlot) chart.getPlot();
		plot.setBackgroundPaint(Color.lightGray);
		plot.setNoDataMessage("No data");

		plot.setDomainGridlinePaint(Color.white);
		plot.setRangeGridlinePaint(Color.white);
		plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
		
		XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
		renderer.setShapesVisible(false);
		renderer.setShapesFilled(false);

		// line color
		renderer.setPaint(info.getSensorColor());

		// horizontal axis - date
		DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
		domainAxis.setTickLabelsVisible(true);
						
		 domainAxis.setDateFormatOverride(new SimpleDateFormat("dd hh:mma"));
		 domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.HOUR,tickInterval));
		 domainAxis.setVerticalTickLabels(true);
		 
		 //whenever one or both of these lines below is uncommented, data isn't plotted
		 //domainAxis.setMaximumDate(lastDate);
		 //domainAxis.setMinimumDate(firstDate);
				
		// Vertical axis
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		
		HashMap<String, Double> minMaxValues = info.getMinMaxValues();
		if (minMaxValues.get("min") != null) {
			rangeAxis.setLowerBound(minMaxValues.get("min"));// Math.floor(minMaxValues.get("min")));
		}
		if (minMaxValues.get("max") != null) {
			rangeAxis.setUpperBound(minMaxValues.get("max")); // Math.ceil(minMaxValues.get("max")));
		}
		
		PanningChartPanel panel = new PanningChartPanel(chart);
Does anyone have any idea why this is happening? I need this to work so that I can display the time period that the client asks for, not just the time period which data is available for.

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Thu Oct 25, 2007 6:01 pm

Have you tried using setRange(...) instead of setMinimumDate()/setMaximumDate()?

annac
Posts: 24
Joined: Mon Oct 01, 2007 7:56 pm
Location: Canada

Post by annac » Thu Oct 25, 2007 7:26 pm

yes I did. I also tried getting double values for the dates and using the setUpper/LowerBound methods. neither worked.

using Calendar instead of Date appears to be working though.

thanks for your suggestions!

annac
Posts: 24
Joined: Mon Oct 01, 2007 7:56 pm
Location: Canada

Post by annac » Thu Oct 25, 2007 8:00 pm

correction, Calendar is working for time periods larger than two weeks (approx?)... not sure why data disappears if time period is smaller than this...

annac
Posts: 24
Joined: Mon Oct 01, 2007 7:56 pm
Location: Canada

Post by annac » Fri Oct 26, 2007 5:52 pm

my fault. I didn't realize that the month index started at 0

Locked