List of usage examples for org.jfree.chart JFreeChart getTitle
public TextTitle getTitle()
From source file:de.aidger.view.utils.Charts.java
/** * Creates a 3D pie chart./*from w w w. j av a 2 s . c om*/ * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * * @return the 3D pie chart as image */ public static ImageIcon createPieChart3D(String title, PieDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getLegend().setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); chart.getLegend().setBorder(0, 0, 0, 0); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setForegroundAlpha(0.9f); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(_("No data to display.")); plot.setLabelGenerator(null); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setDarkerSides(true); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a xy area chart./*w w w. jav a2 s . c o m*/ * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * @return the xy area chart as image */ public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false, false, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); XYPlot plot = chart.getXYPlot(); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setNoDataMessage(_("No data to display.")); ValueAxis domainAxis = new DateAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font")); ValueAxis rangeAxis = new NumberAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); plot.setForegroundAlpha(0.5f); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:electroStaticUI.Save.java
/** * Save chart as SVG file./*from w ww.j a v a2 s .c o m*/ * Required libs: Apache Batik (batik-svggen.jar, batik-dom.jar, dom.jar). * * @param chart JFreeChart to save. * @param fileName Name of file to save chart in. * @param width Width of chart graphic. * @param height Height of chart graphic. * @return Final file name used. * @throws IOException if failed. * * To Do: Add a save/open method for saving a file native to this application. It should save the users current charge distribution * to be re-loaded at a later time. */ static public final String saveChartToSVG(final JFreeChart chart, String fileName, final int width, final int height) throws IOException { String result = null; if (chart != null) { if (fileName == null) { final String chartTitle = chart.getTitle().getText(); if (chartTitle != null) { fileName = chartTitle; } else { fileName = "chart"; } } result = fileName + ".svg"; final DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); final Document document = domImpl.createDocument(null, "svg", null); final SVGGraphics2D svgGenerator = new SVGGraphics2D(document); // svgGenerator.getGeneratorContext().setEmbeddedFontsOn(true); //embed fonts //set anti-aliasing bug fix for SVG generator: //setting rendering hints of svgGenerator doesn't help as it seems to use the rendering hints from the chart final boolean antiAlias = chart.getAntiAlias(); final RenderingHints rh = chart.getRenderingHints(); if (antiAlias) { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); //fix } else { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); //fix } // svgGenerator.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // svgGenerator.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); // svgGenerator.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // svgGenerator.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); // svgGenerator.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // svgGenerator.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), new ChartRenderingInfo()); //undo anti-aliasing bugfix settings for chart to use correct settings: if (antiAlias) { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } final boolean useCSS = true; Writer out = null; try { out = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(new File(result), false)), "iso-8859-1"); //UTF-8 svgGenerator.stream(out, useCSS); } finally { svgGenerator.dispose(); IOUtils.closeQuietly(out); } } //else: input unavailable return result; }
From source file:ec.ui.view.ARPView.java
static JFreeChart createARPChart() { JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); XYPlot plot = result.getXYPlot();//from w w w . ja va2s . c o m plot.setNoDataMessage("Drop data here"); plot.getRangeAxis().setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.getDomainAxis().setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false); return result; }
From source file:ec.ui.view.res.ResidualsView.java
private static JFreeChart buildResidualViewChart() { JFreeChart result = ChartFactory.createXYBarChart("Full residuals", "", false, "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); XYPlot plot = result.getXYPlot();/*from w ww . j a va2 s . co m*/ DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setLowerMargin(0); domainAxis.setUpperMargin(0); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelInsets(new RectangleInsets(10, 5, 10, 2)); rangeAxis.setLowerMargin(0.02); rangeAxis.setUpperMargin(0.02); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); renderer.setDrawBarOutline(true); renderer.setAutoPopulateSeriesPaint(false); renderer.setAutoPopulateSeriesOutlinePaint(false); return result; }
From source file:ec.ui.view.AutoCorrelationsView.java
private static JFreeChart createAutoCorrelationsViewChart() { JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); result.setPadding(TsCharts.CHART_PADDING); XYPlot plot = result.getXYPlot();/* w w w .java2 s . c o m*/ XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); renderer.setDrawBarOutline(true); renderer.setAutoPopulateSeriesPaint(false); renderer.setAutoPopulateSeriesOutlinePaint(false); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); NumberAxis domainAxis = new NumberAxis(); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); return result; }
From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java
/** * @param chart/*from ww w. j ava2 s.com*/ * @return */ private static void configureTitleAndLegend(final JFreeChart chart, final AbstractChart adapter) { final TextTitle title = chart.getTitle(); if (title != null) { title.setFont(new Font("Arial", Font.BOLD, 12)); // title.setBackgroundPaint(Color.CYAN); title.setTextAlignment(HorizontalAlignment.LEFT); title.setHorizontalAlignment(HorizontalAlignment.CENTER); title.setMargin(0, 4, 5, 6); } if (chart.getLegend() != null) { chart.removeLegend(); final LegendTitle legend = new LegendTitle(chart.getPlot(), new SNColumnArrangement(0, 0), new ColumnArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, 0)); legend.setItemFont(LEGEND_FONT); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); legend.setBackgroundPaint(Color.WHITE); legend.setFrame(new LineBorder()); legend.setMargin(0, 4, 5, 6); chart.addLegend(legend); // Now we'll try to remove any duplicate items from the legend.. final Map<String, Integer> keys = new HashMap<String, Integer>(); final LegendItemCollection items = new LegendItemCollection(); for (LegendItemSource source : legend.getSources()) { for (int i = 0; i < source.getLegendItems().getItemCount(); i++) { final LegendItem item = source.getLegendItems().get(i); if (!keys.containsKey(item.getLabel())) { keys.put(item.getLabel(), i); items.add(item); } } } legend.setSources(new LegendItemSource[] { new LegendItemSource() { /* * (non-Javadoc) * * @see org.jfree.chart.LegendItemSource#getLegendItems() */ public LegendItemCollection getLegendItems() { return items; } } }); } }
From source file:com.orsonpdf.demo.PDFPieChartDemo1.java
/** * Creates a chart.// ww w . j a va 2 s. c o m * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", dataset, false, false, false); chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); plot.setShadowPaint(null); plot.setLabelShadowPaint(null); // use gradients and white borders for the section colours plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED)); plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 1.0f); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:org.xapagy.ui.tempdyn.tdVisualizationGenerator.java
/** * Generate a vertical list of JFreeCharts * /* w w w .j av a 2s .c o m*/ * @param labels * - the labels for the values * @param index * - the index * @param values * @return */ public static String generateJFreeChart(List<String> labels, List<Double> index, List<List<Double>> values) { JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); for (int i = 0; i != labels.size(); i++) { XYSeries xys = new XYSeries(labels.get(i)); for (int j = 0; j != index.size(); j++) { xys.add(index.get(j), values.get(i).get(j)); } XYSeriesCollection xysc = new XYSeriesCollection(xys); JFreeChart chart = ChartFactory.createXYLineChart(labels.get(i), "Time", "Focus", xysc, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14)); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); } JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); return null; }
From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java
private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) { JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18)); jfreechart.setBackgroundPaint(new Color(221, 223, 238)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinePaint(Color.gray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); BarRenderer renderer = (BarRenderer) categoryplot.getRenderer(); //categoryplot.setBackgroundPaint(new Color(221, 223, 238)); renderer.setSeriesPaint(0, new Color(130, 165, 70)); renderer.setSeriesPaint(1, new Color(220, 165, 70)); renderer.setSeriesPaint(4, new Color(255, 165, 70)); renderer.setDrawBarOutline(false);/*from ww w .ja v a2 s. co m*/ renderer.setShadowVisible(false); // renderer.setMaximumBarWidth(1); renderer.setGradientPaintTransformer(null); renderer.setDefaultBarPainter(new StandardBarPainter()); categoryplot.setRenderer(renderer); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperMargin(0.25D); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null)); numberaxis.setRange(0, 100); //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12); numberaxis.setTickLabelFont(font); CategoryAxis axisd = categoryplot.getDomainAxis(); ValueAxis axisr = categoryplot.getRangeAxis(); axisd.setTickLabelFont(font); axisr.setTickLabelFont(font); final ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); FileOutputStream output; try { output = new FileOutputStream("successGlobalRates" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, 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); } return jfreechart; }