List of usage examples for org.jfree.chart.title TextTitle setFont
public void setFont(Font font)
From source file:unalcol.termites.boxplots.RoundNumber2.java
/** * Creates a new demo./*from w ww. j a v a 2s . c om*/ * * @param title the frame title. * @param pf */ public RoundNumber2(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); // final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round Number " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("roundnumber2" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 300, 250, null); } catch (FileNotFoundException ex) { Logger.getLogger(RoundNumber2.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RoundNumber2.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.InformationCollected2.java
/** * Creates a new demo./*w w w . j a v a 2s .com*/ * * @param title the frame title. * @param pf */ public InformationCollected2(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("informationcollected2" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 350, 350, null); } catch (FileNotFoundException ex) { Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InformationCollected2.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.HybridRoundNumberReport.java
/** * Creates a new demo.//from w w w .j av a2s . co m * * @param title the frame title. * @param pf */ public HybridRoundNumberReport(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Round number"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 14); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Round Number" + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("roundnumber1" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1350, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(HybridRoundNumberReport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1.java
/** * Creates a Area chart.//from w w w. ja v a 2s . c om * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createAreaChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); if (isDemo) { TextTitle subtitle = new TextTitle("An area chart demonstration. We use this subtitle as an " + "example of what happens when you get a really long title or " + "subtitle."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); if (isDemo) { domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); return chart; }
From source file:nu.nethome.home.items.web.GraphServlet.java
/** * This is the main enterence point of the class. This is called when a http request is * routed to this servlet./*from ww w. java 2s . c o m*/ */ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletOutputStream p = res.getOutputStream(); Date startTime = null; Date stopTime = null; // Analyse arguments String fileName = req.getParameter("file"); if (fileName != null) fileName = getFullFileName(fromURL(fileName)); String startTimeString = req.getParameter("start"); String stopTimeString = req.getParameter("stop"); try { if (startTimeString != null) { startTime = m_Format.parse(startTimeString); } if (stopTimeString != null) { stopTime = m_Format.parse(stopTimeString); } } catch (ParseException e1) { e1.printStackTrace(); } String look = req.getParameter("look"); if (look == null) look = ""; TimeSeries timeSeries = new TimeSeries("Data", Minute.class); // Calculate time window Calendar cal = Calendar.getInstance(); Date currentTime = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date startOfDay = cal.getTime(); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date startOfWeek = cal.getTime(); cal.set(Calendar.DAY_OF_MONTH, 1); Date startOfMonth = cal.getTime(); cal.set(Calendar.MONTH, Calendar.JANUARY); Date startOfYear = cal.getTime(); // if (startTime == null) startTime = startOfWeek; if (stopTime == null) stopTime = currentTime; if (startTime == null) startTime = new Date(stopTime.getTime() - 1000L * 60L * 60L * 24L * 2L); try { // Open the data file File logFile = new File(fileName); Scanner fileScanner = new Scanner(logFile); Long startTimeMs = startTime.getTime(); Long month = 1000L * 60L * 60L * 24L * 30L; boolean doOptimize = true; boolean justOptimized = false; try { while (fileScanner.hasNext()) { try { // Get next log entry String line = fileScanner.nextLine(); if (line.length() > 21) { // Adapt the time format String minuteTime = line.substring(0, 16).replace('.', '-'); // Parse the time stamp Minute min = Minute.parseMinute(minuteTime); // Ok, this is an ugly optimization. If the current time position in the file // is more than a month (30 days) ahead of the start of the time window, we // quick read two weeks worth of data, assuming that there is 4 samples per hour. // This may lead to scanning past start of window if there are holes in the data // series. if (doOptimize && ((startTimeMs - min.getFirstMillisecond()) > month)) { for (int i = 0; (i < (24 * 4 * 14)) && fileScanner.hasNext(); i++) { fileScanner.nextLine(); } justOptimized = true; continue; } // Detect if we have scanned past the window start position just after an optimization scan. // If this is the case it may be because of the optimization. In that case we have to switch // optimization off and start over. if ((min.getFirstMillisecond() > startTimeMs) && doOptimize && justOptimized) { logFile = new File(fileName); fileScanner = new Scanner(logFile); doOptimize = false; continue; } justOptimized = false; // Check if value is within time window if ((min.getFirstMillisecond() > startTimeMs) && (min.getFirstMillisecond() < stopTime.getTime())) { // Parse the value double value = Double.parseDouble((line.substring(20)).replace(',', '.')); // Add the entry timeSeries.add(min, value); doOptimize = false; } } } catch (SeriesException se) { // Bad entry, for example due to duplicates at daylight saving time switch } catch (NumberFormatException nfe) { // Bad number format in a line, try to continue } } } catch (Exception e) { System.out.println(e.toString()); } finally { fileScanner.close(); } } catch (FileNotFoundException f) { System.out.println(f.toString()); } // Create a collection for plotting TimeSeriesCollection data = new TimeSeriesCollection(); data.addSeries(timeSeries); JFreeChart chart; int xSize = 750; int ySize = 450; // Customize colors and look of the Graph. if (look.equals("mobtemp")) { // Look for the mobile GUI chart = ChartFactory.createTimeSeriesChart(null, null, null, data, false, false, false); XYPlot plot = chart.getXYPlot(); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); xSize = 175; ySize = 180; } else { // Create a Chart with time range as heading SimpleDateFormat localFormat = new SimpleDateFormat(); String heading = localFormat.format(startTime) + " - " + localFormat.format(stopTime); chart = ChartFactory.createTimeSeriesChart(heading, null, null, data, false, false, false); Paint background = new Color(0x9D8140); chart.setBackgroundPaint(background); TextTitle title = chart.getTitle(); // fix title Font titleFont = title.getFont(); titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0); title.setFont(titleFont); title.setPaint(Color.darkGray); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.darkGray); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); plot.setRangeGridlinePaint(Color.darkGray); XYItemRenderer renderer = plot.getRenderer(0); renderer.setSeriesPaint(0, Color.darkGray); xSize = 750; ySize = 450; } try { res.setContentType("image/png"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); res.setStatus(HttpServletResponse.SC_OK); ChartUtilities.writeChartAsPNG(p, chart, xSize, ySize); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } p.flush(); p.close(); return; }
From source file:unalcol.termites.boxplots.HybridInformationCollected.java
/** * Creates a new demo.// w ww . j a va2 s. c om * * @param title the frame title. * @param pf */ public HybridInformationCollected(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); final NumberAxis yAxis = new NumberAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 12); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Total of Information Collected " + getTitle(pf), new Font("SansSerif", Font.BOLD, 12), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(1300, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("totalInformationCollected" + pf + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 1300, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(HybridInformationCollected.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(HybridInformationCollected.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java
private static void applyProperties(JFreeChart chart, Map<String, Object> properties) { if (properties != null) { String text = (String) properties.get(TITLE); if (text != null) { TextTitle title = chart.getTitle(); if (title == null) { title = new TextTitle(); chart.setTitle(title);/*from w ww. jav a 2s.co m*/ } title.setText(text); Font titleFont = (Font) properties.get(TITLEFONT); if (titleFont != null) title.setFont(titleFont); Paint paint = (Paint) properties.get(TITLECOLOR); if (paint != null) title.setPaint(paint); } else chart.setTitle((TextTitle) null); Plot plot = chart.getPlot(); Paint paint = (Paint) properties.get(BGCOLOR); if (paint != null) plot.setBackgroundPaint(paint); paint = (Color) properties.get(OUTLINEPAINT); if (paint != null) plot.setOutlinePaint(paint); Stroke stroke = (Stroke) properties.get(OUTLINESTROKE); if (stroke != null) plot.setOutlineStroke(stroke); PlotOrientation orientation = (PlotOrientation) properties.get(ORIENTATION); Axis domainAxis = null; Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); if (orientation != null) p.setOrientation(orientation); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); if (orientation != null) p.setOrientation(orientation); } if (domainAxis != null) applyAxisProperties(domainAxis, "x", properties); //$NON-NLS-1$ if (rangeAxis != null) applyAxisProperties(rangeAxis, "y", properties); //$NON-NLS-1$ Boolean anti = (Boolean) properties.get(ANTIALIAS); if (anti != null) chart.setAntiAlias(anti); paint = (Paint) properties.get(CANVASPAINT); if (paint != null) chart.setBackgroundPaint(paint); } }
From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java
/** Generate CGI chart output. */ @Override/*from w ww .j ava 2 s . c o m*/ protected void writeContents() throws IOException { buildData(); // get the data for display chromeless = (parameters.get("chromeless") != null); JFreeChart chart = createChart(); int width = getIntSetting("width"); int height = getIntSetting("height"); Color initGradColor = getColorSetting("initGradColor"); Color finalGradColor = getColorSetting("finalGradColor"); chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor)); if (parameters.get("hideOutline") != null) chart.getPlot().setOutlinePaint(INVISIBLE); String title = getSetting("title"); if (chromeless || title == null || title.length() == 0) chart.setTitle((TextTitle) null); else { chart.setTitle(Translator.translate(title)); String titleFontSize = getSetting("titleFontSize"); if (titleFontSize != null) try { float fontSize = Float.parseFloat(titleFontSize); TextTitle t = chart.getTitle(); t.setFont(t.getFont().deriveFont(fontSize)); } catch (Exception tfe) { } } if (chromeless || parameters.get("hideLegend") != null) chart.removeLegend(); else { LegendTitle l = chart.getLegend(); String legendFontSize = getSetting("legendFontSize"); if (l != null && legendFontSize != null) try { float fontSize = Float.parseFloat(legendFontSize); l.setItemFont(l.getItemFont().deriveFont(fontSize)); } catch (Exception lfe) { } } chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message")); Axis xAxis = getHorizontalAxis(chart); if (xAxis != null) { if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) { xAxis.setTickLabelsVisible(false); } else if (parameters.get("tickLabelFontSize") != null || parameters.get("xTickLabelFontSize") != null) { String tfs = getParameter("xTickLabelFontSize"); if (tfs == null) tfs = getParameter("tickLabelFontSize"); float fontSize = Float.parseFloat(tfs); xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize)); } } Axis yAxis = getVerticalAxis(chart); if (yAxis != null) { if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) { yAxis.setTickLabelsVisible(false); } else if (parameters.get("tickLabelFontSize") != null || parameters.get("yTickLabelFontSize") != null) { String tfs = getParameter("yTickLabelFontSize"); if (tfs == null) tfs = getParameter("tickLabelFontSize"); float fontSize = Float.parseFloat(tfs); yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize)); } } String axisFontSize = getSetting("axisLabelFontSize"); if (axisFontSize != null) try { float fontSize = Float.parseFloat(axisFontSize); if (xAxis != null) xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize)); if (yAxis != null) yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize)); } catch (Exception afs) { } ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); if ("auto".equals(getSetting("titleFontSize"))) maybeAdjustTitleFontSize(chart, g2, width); chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info); g2.dispose(); String outputFormat = getSetting("outputFormat"); OutputStream imgOut; if (isHtmlMode()) { imgOut = PngCache.getOutputStream(); } else { imgOut = outStream; } ImageIO.write(img, outputFormat, imgOut); imgOut.flush(); imgOut.close(); if (isHtmlMode()) writeImageHtml(width, height, imgOut.hashCode(), info); }
From source file:unalcol.termites.boxplots.MessagesSent1.java
/** * Creates a new demo.//from w ww . ja v a 2s . c o m * * @param title the frame title. * @param pf */ public MessagesSent1(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Messages Sent"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 16); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Messages Sent " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("messagesnumber1" + pf + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.InformationCollected1.java
/** * Creates a new demo.// w w w . j a v a 2 s . c o m * * @param title the frame title. * @param pf */ public InformationCollected1(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); final NumberAxis yAxis = new NumberAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 14); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("informationcollected1" + mazeMode + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(InformationCollected1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InformationCollected1.class.getName()).log(Level.SEVERE, null, ex); } }