List of usage examples for org.jfree.data.time TimeSeries add
public void add(RegularTimePeriod period, Number value)
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private AbstractDataset getTimeSeriesCollectionDataset(Report report) { List<Stat> reportData = report.getReportData(); // fill dataset TimeSeriesCollection dataSet = new TimeSeriesCollection(); String dataSource = report.getReportDefinition().getReportParams().getHowChartSource(); String seriesFrom = report.getReportDefinition().getReportParams().getHowChartSeriesSource(); if (StatsManager.T_TOTAL.equals(seriesFrom) || StatsManager.T_NONE.equals(seriesFrom)) { seriesFrom = null;//from w w w . ja v a 2 s . c o m } Class periodGrouping = null; if (StatsManager.CHARTTIMESERIES_DAY .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod()) || StatsManager.CHARTTIMESERIES_WEEKDAY .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Day.class; } else if (StatsManager.CHARTTIMESERIES_MONTH .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Month.class; } else if (StatsManager.CHARTTIMESERIES_YEAR .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Year.class; } boolean visitsTotalsChart = ReportManager.WHAT_VISITS_TOTALS .equals(report.getReportDefinition().getReportParams().getWhat()) || report.getReportDefinition().getReportParams().getHowTotalsBy().contains(StatsManager.T_VISITS) || report.getReportDefinition().getReportParams().getHowTotalsBy() .contains(StatsManager.T_UNIQUEVISITS); Set<RegularTimePeriod> keys = new HashSet<RegularTimePeriod>(); if (!visitsTotalsChart && seriesFrom == null) { // without additional series String name = msgs.getString("th_total"); TimeSeries ts = new TimeSeries(name, periodGrouping); for (Stat s : reportData) { RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); if (key != null) { Number existing = null; if ((existing = ts.getValue(key)) == null) { ts.add(key, getTotalValue(s, report)); } else { ts.addOrUpdate(key, getTotalValue(existing, s, report)); } keys.add(key); } } dataSet.addSeries(ts); } else if (!visitsTotalsChart && seriesFrom != null) { // with additional series Map<Comparable, TimeSeries> series = new HashMap<Comparable, TimeSeries>(); //TimeSeries ts = new TimeSeries(dataSource, org.jfree.data.time.Day.class); for (Stat s : reportData) { RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); Comparable serie = (Comparable) getStatValue(s, seriesFrom); if (key != null && serie != null) { // determine appropriate serie TimeSeries ts = null; if (!series.containsKey(serie)) { ts = new TimeSeries(serie.toString(), periodGrouping); series.put(serie, ts); } else { ts = series.get(serie); } Number existing = null; if ((existing = ts.getValue(key)) == null) { ts.add(key, getTotalValue(s, report)); } else { ts.addOrUpdate(key, getTotalValue(existing, s, report)); } keys.add(key); } } // add series for (TimeSeries ts : series.values()) { dataSet.addSeries(ts); } } else if (visitsTotalsChart) { // 2 series: visits & unique visitors TimeSeries tsV = new TimeSeries(msgs.getString("th_visits"), periodGrouping); TimeSeries tsUV = new TimeSeries(msgs.getString("th_uniquevisitors"), periodGrouping); for (Stat _s : reportData) { SiteVisits s = (SiteVisits) _s; RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); if (key != null) { Number existing = null; if ((existing = tsV.getValue(key)) == null) { tsV.add(key, s.getTotalVisits()); tsUV.add(key, s.getTotalUnique()); } else { tsV.addOrUpdate(key, s.getTotalVisits() + existing.longValue()); tsUV.addOrUpdate(key, s.getTotalVisits() + existing.longValue()); } keys.add(key); } } dataSet.addSeries(tsV); dataSet.addSeries(tsUV); } // fill missing values with zeros /*for(TimeSeries ts : (List<TimeSeries>) dataSet.getSeries()) { for(RegularTimePeriod tp : keys) { if(ts.getValue(tp) == null) { ts.add(tp, 0.0); } } }*/ dataSet.setXPosition(TimePeriodAnchor.MIDDLE); return dataSet; }
From source file:edu.ucla.stat.SOCR.chart.SuperIntervalXYChart_Time.java
/** * /* w ww .j a va 2 s . c o m*/ * @param isDemo data come from demo(true) or dataTable(false) * @return */ protected IntervalXYDataset createDataset(boolean isDemo) { if (isDemo) { updateStatus("isDemo==true in " + this.getClass().getName() + " class! return null Dataset, check the code!"); return null; } else { setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; double[][] y = new double[xyLength][dependentVarLength]; int[][] skipy = new int[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) { for (int i = 0; i < xyLength; i++) { x[i][index] = indepValues[i][index]; // System.out.println("x["+i+"]["+index+"]="+x[i][index]); } } for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) { if (depValues[i][index] == null || depValues[i][index] == "null" || depValues[i][index] == "NaN" || depValues[i][index].length() == 0) skipy[i][index] = 1; //skip it else y[i][index] = Double.parseDouble(depValues[i][index]); // System.out.println("y["+i+"]["+index+"]="+y[i][index]); } TimeSeriesCollection collection = new TimeSeriesCollection(); TimeSeries series; SimpleDateFormat df = new SimpleDateFormat(); for (int ind = 0; ind < independentVarLength; ind++) { int start_ind = independentHeaders[ind].lastIndexOf(":"); if (start_ind < 0) start_ind = 0; int start_dep = dependentHeaders[ind].lastIndexOf(":"); if (start_dep < 0) start_dep = 0; String serieName = independentHeaders[ind].substring(0, start_ind); if (serieName.length() == 0) serieName = "Serie" + ind; if (start_ind > 0) domainLabel = independentHeaders[ind].substring(0, start_ind); else domainLabel = independentHeaders[ind]; if (start_dep > 0) rangeLabel = dependentHeaders[ind].substring(0, start_dep); else rangeLabel = dependentHeaders[ind]; // series = new TimeSeries(serieName,indName,depName, Year.class); series = new TimeSeries(serieName, Year.class); //TimeSeries("Executions", "Year", "Count", Year.class); try { for (int i = 0; i < xyLength; i++) if (x[i][ind] != null && skipy[i][ind] != 1) { series.add(new Year(Integer.parseInt(x[i][ind])), y[i][ind]); //System.out.println("adding year "+new Year(Integer.parseInt(x[i][ind]))+ " , "+y[i][ind]); } } catch (NumberFormatException e) { SOCROptionPane.showMessageDialog(this, "Wrong data format, enter integer for Year please. Check the Mapping also."); return null; } //System.out.println("adding:"+serieName); // collection.setDomainIsPointsInTime(false); collection.addSeries(series); } return collection; } }
From source file:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java
protected TimeSeriesCollection createTimeSeriesDataset(ChartConfig chartConfig, Document data) { TimeSeriesCollection ds = new TimeSeriesCollection(); for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) { Value value = (Value) i.next();/* w w w. jav a 2s .co m*/ String title = value.getTitle(); Iterator x = XPathUtils.selectIterator(data, value.getCategories()); Iterator y = XPathUtils.selectIterator(data, value.getSeries()); TimeSeries timeSeries = new TimeSeries(title, FixedMillisecond.class); while (x.hasNext() && y.hasNext()) { Node s = (Node) y.next(); Node c = (Node) x.next(); SimpleDateFormat sdf = new SimpleDateFormat(chartConfig.getDateFormat()); FixedMillisecond fm; try { fm = new FixedMillisecond(sdf.parse(c.getStringValue()).getTime()); } catch (java.text.ParseException pe) { throw new OXFException( "Date Format " + chartConfig.getDateFormat() + " does not match with the date data", pe); } Double ordinate = new Double(s.getStringValue()); timeSeries.add(fm, ordinate); } ds.addSeries(timeSeries); } return ds; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java
private XYDataset createInvestDataset() { final Currency localCurrency = org.yccheok.jstock.portfolio.Utils.getLocalCurrency(); final TimeSeries series = new TimeSeries(GUIBundle.getString("InvestmentFlowChartJDialog_Invest")); this.totalInvestValue = 0.0; for (int i = 0, count = this.investSummary.size(); i < count; i++) { final Activities activities = this.investSummary.get(i); double amount = 0.0; for (int j = 0, count2 = activities.size(); j < count2; j++) { final Activity activity = activities.get(j); final Activity.Type type = activity.getType(); final StockInfo stockInfo = (StockInfo) activity.get(Activity.Param.StockInfo); double exchangeRate = org.yccheok.jstock.portfolio.Utils.getExchangeRate( this.portfolioManagementJPanel.getPortfolioRealTimeInfo(), localCurrency, stockInfo.code); if (type == Activity.Type.Buy) { amount += (activity.getAmount() * exchangeRate); } else if (type == Activity.Type.Sell) { amount -= (activity.getAmount() * exchangeRate); } else { assert (false); }//www.j a v a2s . c om } // for (int j = 0, count2 = activities.size(); j < count2; j++) this.totalInvestValue += amount; final SimpleDate date = activities.getDate(); final Date d = date.getTime(); series.add(new Day(d), this.totalInvestValue); } // for (int i = 0, count = this.investSummary.size(); i < count; i++) return new TimeSeriesCollection(series); }
From source file:org.posterita.core.TimeSeriesChart.java
/** * Takes a sql as input and generates a Timeseries that is added to * the dataset. //from w w w . j ava 2s . com * Note: The sql must return 3 columns only Series, date & value * Column 1: Type -> String * Column 2: Type -> String or Date. For String the format must be as dd-MM-yyyy * Column 3: Type -> BigDecimal * * @param sql */ public void getDataSetFromSQL(String sql) throws OperationException { PreparedStatement pstmt = DB.prepareStatement(sql, null); ArrayList<Object[]> dataSource = ReportManager.getReportData(pstmt); int count = 0; String seriesName = null; TimeSeries series = null; BigDecimal value = null; int day = 0; int month = 0; int year = 0; TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); for (Object[] data : dataSource) { if (data.length != 3) throw new OperationException( "Unable to generate timeseries. Cause:Invalid sql, the return resultset must have 3 columns only"); count++; if (count == 1) { continue; } seriesName = (String) data[0]; String date = (String) data[1]; value = (BigDecimal) data[2]; String s[] = date.split("-"); if (s.length != 3) throw new OperationException("Unable to generate timeseries. " + "Cause:Invalid date format, the date returned should have the following format 'DD-MM-YYYY'"); SimpleDateFormat sdf = new SimpleDateFormat(); Calendar cal = Calendar.getInstance(); Date d = null; try { sdf.applyPattern("DD-MM-YYYY"); d = sdf.parse(date); } catch (ParseException e1) { try { sdf.applyPattern("DD-MMM-YYYY"); d = sdf.parse(date); } catch (ParseException e) { throw new OperationException("Unable to generate timeseries. " + "Cause:Invalid date format, the date returned should have one of the following formats 'DD-MM-YYYY' or 'DD-MMM-YYYY'", e); } } cal.setTime(d); day = cal.get(Calendar.DATE); month = cal.get(Calendar.MONTH) + 1; year = cal.get(Calendar.YEAR); series = timeSeriesCollection.getSeries(seriesName); if (series == null) { series = new TimeSeries(seriesName, Day.class); series.add(new Day(day, month, year), value); timeSeriesCollection.addSeries(series); } else { series.add(new Day(day, month, year), value); } //if } //for dataset = timeSeriesCollection; }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
private TimeSeries getPriceTimeSeries(List<ChartData> chartDatas) { // create dataset 1... TimeSeries series1 = new TimeSeries(GUIBundle.getString("ChartJDialog_Price")); for (ChartData chartData : chartDatas) { series1.add(new Day(new Date(chartData.timestamp)), chartData.lastPrice); }/*from w w w . j ava 2 s . c o m*/ return series1; }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
/** * Creates a sample dataset.//from w w w .ja v a2s . c om * * @return A sample dataset. */ private XYDataset getVolumeDataset(List<ChartData> chartDatas) { // create dataset 2... TimeSeries series1 = new TimeSeries(GUIBundle.getString("ChartJDialog_Volume")); for (ChartData chartData : chartDatas) { series1.add(new Day(new Date(chartData.timestamp)), chartData.volume); } return new TimeSeriesCollection(series1); }
From source file:csds60analyzer.csds60analyzerGUI.java
public BufferedImage creaImagen() { BufferedImage imagen = null;/*from w w w . j av a 2 s .c o m*/ try { SAXBuilder builder = new SAXBuilder(false); Document doc = null; TimeSeriesCollection datos = new TimeSeriesCollection(); if (fichero != null) { doc = builder.build(fichero); Element raiz = doc.getRootElement(); List<Element> dias = raiz.getChildren("dia"); Iterator<Element> diasIT = dias.iterator(); TimeSeries desayunoAntes = new TimeSeries("Desayuno antes"); TimeSeries desayunoDespues = new TimeSeries("Desayuno despus"); TimeSeries almuerzoAntes = new TimeSeries("Almuerzo antes"); TimeSeries almuerzoDespues = new TimeSeries("Almuerzo despus"); TimeSeries cenaAntes = new TimeSeries("Cena antes"); TimeSeries cenaDespues = new TimeSeries("Cena despus"); pdesayuno = 0; pdesant = 0; pdesdes = 0; palmuerzo = 0; palmant = 0; palmdes = 0; pcena = 0; pcenant = 0; pcendes = 0; contdesant = 0; contdesdes = 0; contalmant = 0; contalmdes = 0; contcenant = 0; contcendes = 0; while (diasIT.hasNext()) { Element diaActual = diasIT.next(); Integer fechaActual = Integer.parseInt(diaActual.getChildText("fecha").substring(0, 10)); Calendar fad = GregorianCalendar.getInstance(); fad.setTimeInMillis(fechaActual.longValue() * 1000); int dia = fad.get(Calendar.DAY_OF_MONTH); int mes = fad.get(Calendar.MONTH) + 1; int ano = fad.get(Calendar.YEAR); if (diaActual.getChildren().toString().contains("desayunoantes")) { int desayunoAntesActual = Integer.parseInt(diaActual.getChildText("desayunoantes")); desayunoAntes.add(new Day(dia, mes, ano), desayunoAntesActual); pdesant = pdesant + desayunoAntesActual; contdesant++; } if (diaActual.getChildren().toString().contains("desayunodespues")) { int desayunoDespuesActual = Integer.parseInt(diaActual.getChildText("desayunodespues")); desayunoDespues.add(new Day(dia, mes, ano), desayunoDespuesActual); pdesdes = pdesdes + desayunoDespuesActual; contdesdes++; } if (diaActual.getChildren().toString().contains("almuerzoantes")) { int almuerzoAntesActual = Integer.parseInt(diaActual.getChildText("almuerzoantes")); almuerzoAntes.add(new Day(dia, mes, ano), almuerzoAntesActual); palmant = palmant + almuerzoAntesActual; contalmant++; } if (diaActual.getChildren().toString().contains("almuerzodespues")) { int almuerzoDespuesActual = Integer.parseInt(diaActual.getChildText("almuerzodespues")); almuerzoDespues.add(new Day(dia, mes, ano), almuerzoDespuesActual); palmdes = palmdes + almuerzoDespuesActual; contalmdes++; } if (diaActual.getChildren().toString().contains("cenaantes")) { int cenaAntesActual = Integer.parseInt(diaActual.getChildText("cenaantes")); cenaAntes.add(new Day(dia, mes, ano), cenaAntesActual); pcenant = pcenant + cenaAntesActual; contcenant++; } if (diaActual.getChildren().toString().contains("cenadespues")) { int cenaDespuesActual = Integer.parseInt(diaActual.getChildText("cenadespues")); cenaDespues.add(new Day(dia, mes, ano), cenaDespuesActual); pcendes = pcendes + cenaDespuesActual; contcendes++; } } //controlar la division por cero if ((contdesant + contdesdes) > 0) pdesayuno = (pdesant + pdesdes) / (contdesant + contdesdes); if (contdesant > 0) pdesant = pdesant / contdesant; if (contdesdes > 0) pdesdes = pdesdes / contdesdes; if ((contalmant + contalmdes) > 0) palmuerzo = (palmant + palmdes) / (contalmant + contalmdes); if (contalmant > 0) palmant = palmant / contalmant; if (contalmdes > 0) palmdes = palmdes / contalmdes; if ((contcenant + contcendes) > 0) pcena = (pcenant + pcendes) / (contcenant + contcendes); if (contcenant > 0) pcenant = pcenant / contcenant; if (contcendes > 0) pcendes = pcendes / contcendes; datos.addSeries(desayunoAntes); datos.addSeries(desayunoDespues); datos.addSeries(almuerzoAntes); datos.addSeries(almuerzoDespues); datos.addSeries(cenaAntes); datos.addSeries(cenaDespues); } JFreeChart graficaJfree = ChartFactory.createTimeSeriesChart("Anlisis", " ", "Glucosa (mg)", datos, true, true, false); XYPlot plot = (XYPlot) graficaJfree.getPlot(); plot.setBackgroundPaint(Color.getHSBColor(0f, 0f, .88f)); plot.setDomainGridlinePaint(Color.getHSBColor(0f, 0f, .35f)); plot.setDomainTickBandPaint(Color.getHSBColor(0f, 0f, .93f)); plot.setOutlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); plot.setRangeGridlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); XYLineAndShapeRenderer plot2 = (XYLineAndShapeRenderer) plot.getRenderer(); if (!CBdesayunoantes.getState()) plot2.setSeriesLinesVisible(0, false); plot2.setSeriesPaint(0, Color.getHSBColor(.3f, 1f, .5f)); //plot2.setSeriesStroke(0,new BasicStroke(2.0f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND,1.0f)); if (!CBdesayunodespues.getState()) plot2.setSeriesLinesVisible(1, false); plot2.setSeriesPaint(1, Color.getHSBColor(.2f, 1f, .9f)); if (!CBalmuerzoantes.getState()) plot2.setSeriesLinesVisible(2, false); plot2.setSeriesPaint(2, Color.getHSBColor(.0f, 1f, .6f)); if (!CBalmuerzodespues.getState()) plot2.setSeriesLinesVisible(3, false); plot2.setSeriesPaint(3, Color.getHSBColor(.0f, 1f, .9f)); if (!CBcenaantes.getState()) plot2.setSeriesLinesVisible(4, false); plot2.setSeriesPaint(4, Color.getHSBColor(.6f, 1f, .4f)); if (!CBcenadespues.getState()) plot2.setSeriesLinesVisible(5, false); plot2.setSeriesPaint(5, Color.getHSBColor(.6f, 1f, 1f)); imagen = graficaJfree.createBufferedImage(800, 600); } catch (Exception e) { e.printStackTrace(); } return imagen; }
From source file:beproject.MainGUI.java
private TimeSeriesCollection timeLinePlot() { final TimeSeries relaxed = new TimeSeries("Relaxed"); final TimeSeries happy = new TimeSeries("Happy"); final TimeSeries unhappy = new TimeSeries("Unhappy"); final TimeSeries upset = new TimeSeries("Upset"); int r = 0, h = 0, u = 0, p = 0; ResultSet rs = null;//Regression.getOneHourTweets(15, movieName); try {/*from w w w . j a va 2s . com*/ while (rs.next()) { int tmp = rs.getInt(4); if (tmp > 0.5) { r++; } else if (tmp >= 0) { h++; } else if (tmp > -0.5) { u++; } else { p++; } } } catch (SQLException e) { } relaxed.add(new Second(), r); happy.add(new Second(), h); unhappy.add(new Second(), -u); upset.add(new Second(), -p); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(relaxed); dataset.addSeries(happy); dataset.addSeries(unhappy); dataset.addSeries(upset); return dataset; }
From source file:org.adempiere.apps.graph.ChartBuilder.java
private void addData(MChartDatasource ds) { String value = ds.getValueColumn(); String category;/*from w ww .j a v a 2s . c o m*/ String unit = "D"; if (!chartModel.isTimeSeries()) category = ds.getCategoryColumn(); else { if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Week)) { unit = "W"; } else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Month)) { unit = "MM"; } else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Quarter)) { unit = "Q"; } else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Year)) { unit = "Y"; } category = " TRUNC(" + ds.getDateColumn() + ", '" + unit + "') "; } String series = DB.TO_STRING(ds.getName()); boolean hasSeries = false; if (ds.getSeriesColumn() != null) { series = ds.getSeriesColumn(); hasSeries = true; } String where = ds.getWhereClause(); if (!Util.isEmpty(where)) { where = Env.parseContext(Env.getCtx(), chartModel.getWindowNo(), where, true); } boolean hasWhere = false; String sql = "SELECT " + value + ", " + category + ", " + series + " FROM " + ds.getFromClause(); if (!Util.isEmpty(where)) { sql += " WHERE " + where; hasWhere = true; } Date currentDate = Env.getContextAsDate(Env.getCtx(), "#Date"); Date startDate = null; Date endDate = null; int scope = chartModel.getTimeScope(); int offset = ds.getTimeOffset(); if (chartModel.isTimeSeries() && scope != 0) { offset += -scope; startDate = increment(currentDate, chartModel.getTimeUnit(), offset); endDate = increment(startDate, chartModel.getTimeUnit(), scope); } if (startDate != null && endDate != null) { sql += hasWhere ? " AND " : " WHERE "; sql += category + ">=TRUNC(" + DB.TO_DATE(new Timestamp(startDate.getTime())) + ", '" + unit + "') AND "; sql += category + "<=TRUNC(" + DB.TO_DATE(new Timestamp(endDate.getTime())) + ", '" + unit + "') "; } if (sql.indexOf('@') >= 0) { sql = Env.parseContext(Env.getCtx(), 0, sql, false, true); } MRole role = MRole.getDefault(Env.getCtx(), false); sql = role.addAccessSQL(sql, null, true, false); if (hasSeries) sql += " GROUP BY " + series + ", " + category + " ORDER BY " + series + ", " + category; else sql += " GROUP BY " + category + " ORDER BY " + category; log.log(Level.FINE, sql); PreparedStatement pstmt = null; ResultSet rs = null; TimeSeries tseries = null; Dataset dataset = getDataset(); try { pstmt = DB.prepareStatement(sql, null); rs = pstmt.executeQuery(); while (rs.next()) { String key = rs.getString(2); String seriesName = rs.getString(3); if (seriesName == null) seriesName = ds.getName(); String queryWhere = ""; if (hasWhere) queryWhere += where + " AND "; queryWhere += series + " = " + DB.TO_STRING(seriesName) + " AND " + category + " = "; if (chartModel.isTimeSeries() && dataset instanceof TimeSeriesCollection) { if (tseries == null || !tseries.getKey().equals(seriesName)) { if (tseries != null) ((TimeSeriesCollection) dataset).addSeries(tseries); tseries = new TimeSeries(seriesName); } Date date = rs.getDate(2); RegularTimePeriod period = null; if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Day)) period = new Day(date); else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Week)) period = new Week(date); else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Month)) period = new Month(date); else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Quarter)) period = new Quarter(date); else if (chartModel.getTimeUnit().equals(MChart.TIMEUNIT_Year)) period = new Year(date); tseries.add(period, rs.getBigDecimal(1)); key = period.toString(); queryWhere += DB.TO_DATE(new Timestamp(date.getTime())); } else { queryWhere += DB.TO_STRING(key); } MQuery query = new MQuery(ds.getAD_Table_ID()); String keyCol = MTable.get(Env.getCtx(), ds.getAD_Table_ID()).getKeyColumns()[0]; String whereClause = keyCol + " IN (SELECT " + ds.getKeyColumn() + " FROM " + ds.getFromClause() + " WHERE " + queryWhere + " )"; query.addRestriction(whereClause.toString()); query.setRecordCount(1); HashMap<String, MQuery> map = getQueries(); if (dataset instanceof DefaultPieDataset) { ((DefaultPieDataset) dataset).setValue(key, rs.getBigDecimal(1)); map.put(key, query); } else if (dataset instanceof DefaultCategoryDataset) { ((DefaultCategoryDataset) dataset).addValue(rs.getBigDecimal(1), seriesName, key); map.put(seriesName + "__" + key, query); } else if (dataset instanceof TimeSeriesCollection) { map.put(seriesName + "__" + key, query); } } } catch (SQLException e) { throw new DBException(e, sql); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } if (tseries != null) ((TimeSeriesCollection) dataset).addSeries(tseries); }