Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java @ 324:e6e172a4915e
Removed needless imports.
gnv-artifacts/trunk@387 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 30 Nov 2009 15:08:47 +0000 |
parents | 63f8b3fb7d9a |
children | 22a6493e8460 |
line wrap: on
line source
package de.intevation.gnv.chart; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Iterator; import java.util.Locale; import org.apache.log4j.Logger; import org.jfree.chart.ChartTheme; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.general.Series; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.Minute; import org.jfree.data.time.TimeSeriesCollection; import de.intevation.gnv.geobackend.base.Result; /** * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> */ public class TimeSeriesChart extends AbstractXYLineChart { private static final String DATE_FORMAT = "dd-MMM"; private static Logger log = Logger.getLogger(TimeSeriesChart.class); public TimeSeriesChart( ChartLabels labels, ChartTheme theme, Collection parameters, Collection measurements, Collection dates, Collection result, Collection timeGaps, Locale locale ) { this.labels = labels; this.theme = theme; this.parameters = parameters; this.measurements = measurements; this.dates = dates; this.resultSet = result; this.timeGaps = timeGaps; this.locale = locale; this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; } public JFreeChart generateChart() { log.debug("generate timeseries chart"); if (chart != null) return chart; chart = ChartFactory.createTimeSeriesChart( labels.getTitle(), labels.getDomainAxisLabel(), null, null, true, false, false ); theme.apply(chart); initData(); return chart; } protected void initData() { log.debug("init data for timeseries chart"); String breakPoint1 = null; String breakPoint2 = null; String breakPoint3 = null; Iterator iter = resultSet.iterator(); Result row = null; String seriesName = null; TimeSeries series = null; int idx = 0; while (iter.hasNext()) { row = (Result) iter.next(); // add current data to plot and prepare for next one if (!row.getString("GROUP1").equals(breakPoint1) || !row.getString("GROUP2").equals(breakPoint2) || !row.getString("GROUP3").equals(breakPoint3) ) { log.debug("prepare data/plot for next dataset"); if(series != null) { addSeries(series, idx); prepareAxis(((String)series.getKey()), idx++); } // prepare variables for next plot breakPoint1 = row.getString("GROUP1"); breakPoint2 = row.getString("GROUP2"); breakPoint3 = row.getString("GROUP3"); seriesName = createSeriesName( breakPoint1, breakPoint2, breakPoint3 ); log.debug("next dataset is '" + seriesName + "'"); series = new TimeSeries(seriesName, Minute.class); } addValue(row, series); } // add the last dataset if existing to plot and prepare its axis addSeries(series, idx); if (series != null) prepareAxis(((String)series.getKey()), idx++); } protected void addValue(Result row, Series series) { // TODO look for gaps between two values ((TimeSeries) series).addOrUpdate( new Minute(row.getDate("XORDINATE")), row.getDouble("YORDINATE") ); } protected void addSeries(Series series, int idx) { log.debug("add series to timeseries chart"); XYPlot plot = chart.getXYPlot(); if (series == null) { log.warn("no data to add"); return; } TimeSeriesCollection tsc = new TimeSeriesCollection((TimeSeries)series); plot.setDataset(idx, tsc); } protected void localizeDomainAxis(Axis axis, Locale locale) { if (locale == null) return; log.debug( "Set language of axis [" + axis.getLabel() + "] " + "to " + locale.toString() ); DateFormat format = new SimpleDateFormat(DATE_FORMAT, locale); ((DateAxis) axis).setDateFormatOverride(format); } protected String createSeriesName( String breakPoint1, String breakPoint2, String breakPoint3 ) { log.debug("create seriesname of timeseries chart"); return findValueTitle(parameters, breakPoint1) + " " + findValueTitle(measurements, breakPoint2) + "m"; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :