List of usage examples for org.jfree.chart ChartFactory createTimeSeriesChart
public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:com.julius.BmiFrame.java
private void ourInit() { jPanel6.setLayout(new BorderLayout()); XYDataset xd = createDataset();//from ww w. ja v a2s. co m JFreeChart chart = ChartFactory.createTimeSeriesChart("BMI as a function of time.", // title "Date", // x-axis label "BMI", // y-axis label xd, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); //plot.setWeight(); jPanel7 = new ChartPanel(chart); jPanel6.add(jPanel7, BorderLayout.CENTER); jPanel6.validate(); }
From source file:Main.Interface_Main.java
private JFreeChart createChartDp(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("D+", "Time", "Volts", dataset, false, true, false);//w w w . j a v a2s .c o m final XYPlot plot = result.getXYPlot(); XYItemRenderer xyir = plot.getRenderer(); xyir.setSeriesPaint(0, Color.GREEN); plot.setBackgroundPaint(Color.BLACK); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis = plot.getRangeAxis(); axis.setRange(0.0, 5.2); return result; }
From source file:org.n52.server.io.render.DiagramRenderer.java
private JFreeChart initializeTimeSeriesChart() { String title = null;/*from w ww.java 2 s . c o m*/ String xLabel = "Date"; String yLabel = ""; XYDataset data = null; boolean isCreateLegend = false; boolean isCreateTooltips = true; boolean isCreateURLs = true; return ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, data, isCreateLegend, isCreateTooltips, isCreateURLs); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java
private synchronized JFreeChart createChart() { initSummaries(this.portfolioManagementJPanel); final XYDataset priceData = this.createInvestDataset(); JFreeChart chart = ChartFactory.createTimeSeriesChart(" ", GUIBundle.getString("InvestmentFlowChartJDialog_Date"), GUIBundle.getString("InvestmentFlowChartJDialog_Value"), priceData, true, // create legend? true, // generate tooltips? false // generate URLs? );/*from w w w.j a v a 2 s .c o m*/ XYPlot plot = chart.getXYPlot(); NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); final String currencySymbol = jStockOptions.getCurrencySymbol(jStockOptions.getCountry()); // Use apostrophes to escape currencySymbol. If currencySymbol contains // apostrophes, we may need to escape those by doubling them. // // 0 decimal place, to save up some display area. final NumberFormat currencyFormat = new DecimalFormat("'" + currencySymbol.replace("'", "''") + "'#,##0"); rangeAxis1.setNumberFormatOverride(currencyFormat); plot.setRenderer(1, new StandardXYItemRenderer()); this.ROITimeSeries = new TimeSeries(GUIBundle.getString("InvestmentFlowChartJDialog_ReturnOfInvestment")); plot.setDataset(1, new TimeSeriesCollection(this.ROITimeSeries)); this.updateROITimeSeries(); return chart; }
From source file:com.android.ddmuilib.log.event.EventDisplay.java
Control createCompositeChart(final Composite parent, EventLogParser logParser, String title) { mChart = ChartFactory.createTimeSeriesChart(null, null /* timeAxisLabel */, null /* valueAxisLabel */, null, /* dataset. set below */ true /* legend */, false /* tooltips */, false /* urls */); // get the font to make a proper title. We need to convert the swt font, // into an awt font. Font f = parent.getFont();/* w w w .ja v a2 s.c o m*/ FontData[] fData = f.getFontData(); // event though on Mac OS there could be more than one fontData, we'll only use // the first one. FontData firstFontData = fData[0]; java.awt.Font awtFont = SWTUtils.toAwtFont(parent.getDisplay(), firstFontData, true /* ensureSameSize */); mChart.setTitle(new TextTitle(title, awtFont)); final XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setRangeCrosshairVisible(true); xyPlot.setRangeCrosshairLockedOnData(true); xyPlot.setDomainCrosshairVisible(true); xyPlot.setDomainCrosshairLockedOnData(true); mChart.addChangeListener(new ChartChangeListener() { @Override public void chartChanged(ChartChangeEvent event) { ChartChangeEventType type = event.getType(); if (type == ChartChangeEventType.GENERAL) { // because the value we need (rangeCrosshair and domainCrosshair) are // updated on the draw, but the notification happens before the draw, // we process the click in a future runnable! parent.getDisplay().asyncExec(new Runnable() { @Override public void run() { processClick(xyPlot); } }); } } }); mChartComposite = new ChartComposite(parent, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 3000, // max draw width. We don't want it to zoom, so we put a big number 3000, // max draw height. We don't want it to zoom, so we put a big number true, // off-screen buffer true, // properties true, // save true, // print true, // zoom true); // tooltips mChartComposite.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { mValueTypeDataSetMap.clear(); mDataSetCount = 0; mOccurrenceDataSet = null; mChart = null; mChartComposite = null; mValueDescriptorSeriesMap.clear(); mOcurrenceDescriptorSeriesMap.clear(); } }); return mChartComposite; }
From source file:org.n52.server.io.render.DiagramRenderer.java
protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap, String[] observedProperties, ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) { JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title "Date", // x-axis label observedProperties[0], // y-axis label timeSeries.get(0), // data true, // create legend? true, // generate tooltips? false // generate URLs? );//from w w w. jav a 2 s. com chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // add additional datasets: DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setRange(begin.getTime(), end.getTime()); axis.setDateFormatOverride(new SimpleDateFormat()); axis.setTimeZone(end.getTimeZone()); for (int i = 1; i < observedProperties.length; i++) { XYDataset additionalDataset = timeSeries.get(i); plot.setDataset(i, additionalDataset); plot.setRangeAxis(i, new NumberAxis(observedProperties[i])); // plot.getRangeAxis(i).setRange((Double) // overAllSeriesCollection.getMinimum(i), // (Double) overAllSeriesCollection.getMaximum(i)); plot.mapDatasetToRangeAxis(i, i); // plot.getDataset().getXValue(i, i); } return chart; }
From source file:Main.Interface_Main.java
private JFreeChart createChartDm(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("D-", "Time", "Volts", dataset, false, true, false);/*from ww w.j a va 2 s. c om*/ final XYPlot plot = result.getXYPlot(); XYItemRenderer xyir = plot.getRenderer(); xyir.setSeriesPaint(0, Color.GREEN); plot.setBackgroundPaint(Color.BLACK); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis = plot.getRangeAxis(); axis.setRange(0.0, 5.2); return result; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getDaily2Stats(Session s) { JFreeChart chart;//from w ww. ja v a 2 s. co m List<DailyStatsModel> stats = (new SafeHibList<DailyStatsModel>( s.createQuery("select ds from DailyStatsModel as ds where day<? and day>=? order by day desc") .setDate(0, new Date()).setDate(1, GraphServlet.getStartDate()))).list(); TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeries signups = new TimeSeries("signups", Day.class); theData.addSeries(signups); TimeSeries mlSignups = new TimeSeries("Mailing list signups", Day.class); theData.addSeries(mlSignups); TimeSeries mlUpgrades = new TimeSeries("Mailing list upgrades", Day.class); theData.addSeries(mlUpgrades); TimeSeries deletions = new TimeSeries("Deletions", Day.class); theData.addSeries(deletions); for (DailyStatsModel ds : stats) { Day theDay = new Day(ds.getDay()); signups.add(theDay, ds.getSignups()); deletions.add(theDay, ds.getDeletions()); mlSignups.add(theDay, ds.getMailinglistsignups()); mlUpgrades.add(theDay, ds.getMailinglistupgrades()); } chart = ChartFactory.createTimeSeriesChart("Account changes (14-day moving avg)", "Day", "Occurrences", MovingAverage.createMovingAverage(theData, "", 14, 0), true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRangeAxis().setUpperBound(25); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f)); renderer.setSeriesStroke(3, new BasicStroke(2.0f)); return chart; }
From source file:oscar.form.study.hsfo2.pageUtil.ManageHSFOAction.java
public void generateGraphs(HttpServletRequest request, HttpServletResponse response, Map<GraphDesc, TimeSeries> graphDescSeriesMap) { if (graphDescSeriesMap == null || graphDescSeriesMap.size() == 0) return;//from w w w . j av a2 s .c o m OscarProperties props = OscarProperties.getInstance(); String graphDirPath = props.getProperty("hsfo2.generategraph.dir", "/hsfo2Graphs"); //graphDirPath = this.getServlet().getServletContext().getContextPath() + "/" + graphDirPath; //graphDirPath = request.getContextPath() + "/" + graphDirPath; String graphDirRealPath = getServlet().getServletContext().getRealPath(graphDirPath); //make sure the directory exists File graphDir = new File(graphDirRealPath); if (!graphDir.exists() || !graphDir.isDirectory()) { graphDir.mkdirs(); } for (Map.Entry<GraphDesc, TimeSeries> entry : graphDescSeriesMap.entrySet()) { //one dataset only contain one series here GraphDesc graphDesc = entry.getKey(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(entry.getValue()); JFreeChart chart = ChartFactory.createTimeSeriesChart(graphDesc.getGraphTitle(), graphDesc.getXAxisLabel(), graphDesc.getYAxisLabel(), dataset, true, true, true); //might need to adjust the XYPlot, see Line 459 of MeasurementGraphAction2 try { String fileName = graphDesc.getFileName() + "." + Calendar.getInstance().getTimeInMillis() + ".jpg"; String realFilePath = graphDirRealPath + "/" + fileName; ChartUtilities.saveChartAsJPEG(new File(realFilePath), chart, 900, 200); logger.info("graph file: " + realFilePath + " generated and saved. "); request.setAttribute("graphFile." + graphDesc.getFileName(), request.getContextPath() + "/" + graphDirPath + "/" + fileName); } catch (IOException e) { logger.error("Problem in creating chart: " + e.toString()); } } }
From source file:org.n52.server.sos.render.DiagramRenderer.java
protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap, String[] observedProperties, ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) { JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title "Date", // x-axis label observedProperties[0], // y-axis label timeSeries.get(0), // data true, // create legend? true, // generate tooltips? false // generate URLs? );//from w ww . j av a2 s. co m chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // add additional datasets: DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setRange(begin.getTime(), end.getTime()); axis.setDateFormatOverride(new SimpleDateFormat()); for (int i = 1; i < observedProperties.length; i++) { XYDataset additionalDataset = timeSeries.get(i); plot.setDataset(i, additionalDataset); plot.setRangeAxis(i, new NumberAxis(observedProperties[i])); // plot.getRangeAxis(i).setRange((Double) // overAllSeriesCollection.getMinimum(i), // (Double) overAllSeriesCollection.getMaximum(i)); plot.mapDatasetToRangeAxis(i, i); // plot.getDataset().getXValue(i, i); } return chart; }