List of usage examples for org.jfree.chart JFreeChart addSubtitle
public void addSubtitle(Title subtitle)
From source file:org.jfree.chart.demo.XYBlockChartDemo2.java
private static JFreeChart createChart(XYZDataset xyzdataset) { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setLowerMargin(0.0D);/*from ww w . j a v a 2 s . c o m*/ dateaxis.setUpperMargin(0.0D); dateaxis.setInverted(true); NumberAxis numberaxis = new NumberAxis("Hour"); numberaxis.setUpperMargin(0.0D); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBlockRenderer xyblockrenderer = new XYBlockRenderer(); xyblockrenderer.setBlockWidth(86400000D); xyblockrenderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 4.5D, Color.white); lookuppaintscale.add(0.5D, Color.red); lookuppaintscale.add(1.5D, Color.green); lookuppaintscale.add(2.5D, Color.blue); lookuppaintscale.add(3.5D, Color.yellow); xyblockrenderer.setPaintScale(lookuppaintscale); XYPlot xyplot = new XYPlot(xyzdataset, dateaxis, numberaxis, xyblockrenderer); xyplot.setOrientation(PlotOrientation.HORIZONTAL); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo2", xyplot); jfreechart.removeLegend(); jfreechart.setBackgroundPaint(Color.white); SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "Unavailable", "Free", "Group 1", "Group 2" }); symbolaxis.setRange(0.5D, 4.5D); symbolaxis.setPlot(new PiePlot()); symbolaxis.setGridBandsVisible(false); PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis); paintscalelegend.setMargin(new RectangleInsets(3D, 10D, 3D, 10D)); paintscalelegend.setPosition(RectangleEdge.BOTTOM); paintscalelegend.setAxisOffset(5D); jfreechart.addSubtitle(paintscalelegend); return jfreechart; }
From source file:org.gaixie.micrite.jfreechart.style.PieStyle.java
/** * ?2???block//from w w w .ja v a 2 s . co m * <p> * ? LegendTitle * @param chart JFreeChart */ public static void styleTwo(JFreeChart chart) { PiePlot plot = (PiePlot) chart.getPlot(); PieStyle.setBackground(chart); // LegendTitleblockblock BlockContainer block = new BlockContainer(new BorderArrangement()); block.setBorder(new BlockBorder(1.0D, 1.0D, 1.0D, 1.0D)); // LegendTitleblock LegendTitle legend = new LegendTitle(plot); BlockContainer legendBlock = legend.getItemContainer(); // legendBlockblock? block.add(legendBlock); legend.setWrapper(block); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); //label plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); }
From source file:org.jfree.fx.demo.FXGraphics2DDemo1.java
/** * Creates a chart./*from w w w . j a va 2s .c om*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("International Coffee Organisation : Coffee Prices", // title null, // x-axis label "US cents/lb", // y-axis label dataset); String fontName = "Palatino"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); renderer.setDefaultStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, new Color(24, 123, 58)); renderer.setSeriesPaint(2, new Color(149, 201, 136)); renderer.setSeriesPaint(3, new Color(1, 62, 29)); renderer.setSeriesPaint(4, new Color(81, 176, 86)); renderer.setSeriesPaint(5, new Color(0, 55, 122)); renderer.setSeriesPaint(6, new Color(0, 92, 165)); } return chart; }
From source file:org.opennms.netmgt.charts.ChartUtils.java
/** * @param chartConfig/*w ww . j a v a2s . co m*/ * @param barChart */ private static void addSubTitles(BarChart chartConfig, JFreeChart barChart) { Iterator<SubTitle> it; /* * Add subtitles. */ for (it = chartConfig.getSubTitleCollection().iterator(); it.hasNext();) { SubTitle subTitle = (SubTitle) it.next(); Title title = subTitle.getTitle(); String value = title.getValue(); barChart.addSubtitle(new TextTitle(value)); } }
From source file:org.jfree.chart.demo.AreaChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = 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."); texttitle.setFont(new Font("SansSerif", 0, 12)); texttitle.setPosition(RectangleEdge.TOP); texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D, 0.050000000000000003D, 0.050000000000000003D)); texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM); jfreechart.addSubtitle(texttitle); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setForegroundAlpha(0.5F); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinesVisible(true); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setRangeGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); categoryaxis.setLowerMargin(0.0D);// w w w . j a va 2 s . c om categoryaxis.setUpperMargin(0.0D); categoryaxis.addCategoryLabelToolTip("Type 1", "The first type."); categoryaxis.addCategoryLabelToolTip("Type 2", "The second type."); categoryaxis.addCategoryLabelToolTip("Type 3", "The third type."); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setLabelAngle(0.0D); return jfreechart; }
From source file:cz.muni.fi.nbs.utils.Helpers.java
private static void exportToPNG(Map<String, Collection<Result>> results) { for (Entry<String, Collection<Result>> entry : results.entrySet()) { double number = 0; String key = entry.getKey(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Iterator<Result> resultsIterator = results.get(key).iterator(); while (resultsIterator.hasNext()) { Result r = resultsIterator.next(); dataset.addValue(r.getScore(), r.getLabel(), ""); number += 0.8;//from ww w. j a va 2s. co m } double width = number > 1 ? number * 200 : 300; String unit = entry.getValue().iterator().next().getScoreUnit(); String[] splitKey = key.split("_"); JFreeChart chart = ChartFactory.createBarChart3D(splitKey[0], null, unit, dataset); int len = splitKey.length / 2; for (int i = 0; i < len; i++) { String subtitle = splitKey[i * 2 + 1] + ":" + splitKey[i * 2 + 2]; TextTitle title = new TextTitle(subtitle); Font oldFont = title.getFont(); int fontSize = (int) Math.round(oldFont.getSize() * 1.2); int fontStyle = oldFont.getStyle(); String fontName = oldFont.getName(); title.setFont(new Font(fontName, fontStyle, fontSize)); chart.addSubtitle(title); } try { ChartUtilities.saveChartAsPNG(new File(resultsDir + "/charts/" + key + "Chart.png"), chart, (int) Math.round(width), 800); } catch (IOException ex) { Logger.getLogger(Helpers.class.getName()).log(Level.SEVERE, "Could not export chart to PNG file for " + key, ex); } } }
From source file:org.jfree.chart.demo.ThumbnailDemo1.java
private static JFreeChart createChart3(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Public Opinion : Torture of Prisoners", "Country", "%", categorydataset, PlotOrientation.HORIZONTAL, false, true, false); jfreechart.getTitle().setMargin(2D, 0.0D, 0.0D, 0.0D); TextTitle texttitle = new TextTitle("Source: http://news.bbc.co.uk/1/hi/world/6063386.stm", new Font("Dialog", 0, 11)); texttitle.setPosition(RectangleEdge.BOTTOM); texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT); texttitle.setMargin(0.0D, 0.0D, 4D, 4D); jfreechart.addSubtitle(texttitle); TextTitle texttitle1 = new TextTitle("(*) Across 27,000 respondents in 25 countries", new Font("Dialog", 0, 11)); texttitle1.setPosition(RectangleEdge.BOTTOM); texttitle1.setHorizontalAlignment(HorizontalAlignment.RIGHT); texttitle1.setMargin(4D, 0.0D, 2D, 4D); jfreechart.addSubtitle(texttitle1);/*from w w w . j a va 2 s . co m*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); LegendItemCollection legenditemcollection = new LegendItemCollection(); legenditemcollection.add(new LegendItem("Against all torture", null, null, null, new java.awt.geom.Rectangle2D.Double(-6D, -3D, 12D, 6D), Color.green)); legenditemcollection.add(new LegendItem("Some degree permissible", null, null, null, new java.awt.geom.Rectangle2D.Double(-6D, -3D, 12D, 6D), Color.red)); categoryplot.setFixedLegendItems(legenditemcollection); categoryplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D)); LegendTitle legendtitle = new LegendTitle(categoryplot); legendtitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(legendtitle); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setDomainGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setUpperMargin(0.0D); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0)); Color color = new Color(0, 0, 0, 0); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); barrenderer.setSeriesPaint(0, gradientpaint); barrenderer.setSeriesPaint(1, color); barrenderer.setSeriesPaint(2, gradientpaint1); return jfreechart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * //from w ww.j a v a 2 s . c o m * DOC zshen Comment method "createMatchRuleBarChart". * * @param title * @param dataset * @return */ public static JFreeChart createMatchRuleBarChart(String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset) { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart localJFreeChart = ChartFactory.createBarChart(null, categoryAxisLabel, valueAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); localJFreeChart.addSubtitle(new TextTitle( Messages.getString("DataChart.title", sumItemCount(dataset), sumGroupCount(dataset)))); //$NON-NLS-1$ CategoryPlot plot = (CategoryPlot) localJFreeChart.getPlot(); // get real color list from ChartDecorator.COLOR_LIST dataset.getColumnKeys() List<Color> currentColorList = null; try { currentColorList = getCurrentColorList(dataset.getColumnKeys()); } catch (NumberFormatException e) { log.warn(e, e); currentColorList = ChartDecorator.COLOR_LIST; } BarRenderer barRenderer = new TalendBarRenderer(true, currentColorList); barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); barRenderer.setBaseItemLabelsVisible(true); // remove the shadow barRenderer.setShadowVisible(Boolean.FALSE); plot.setRenderer(barRenderer); CategoryAxis localCategoryAxis = plot.getDomainAxis(); localCategoryAxis.setCategoryMargin(0.25D); localCategoryAxis.setUpperMargin(0.02D); localCategoryAxis.setLowerMargin(0.02D); NumberAxis localNumberAxis = (NumberAxis) plot.getRangeAxis(); localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); localNumberAxis.setUpperMargin(0.1D); return localJFreeChart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
public static JFreeChart createXYBlockChart(IXYZDataset dataset) { NumberAxis xAxis = createXAxis(dataset); NumberAxis yAxis = createYAxis(dataset); NumberAxis scaleAxis = createScaleAxis(dataset); float min = (float) dataset.getZMin(); float max = (float) dataset.getZMax(); PaintScale scale = generateRainbowScale(min, max, StaticValues.DEFAULT_COLOR_SCALE); XYBlockRenderer renderer = createRender(dataset, scale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); plot.setDomainPannable(true);/* ww w .j a va2s . com*/ plot.setRangePannable(true); JFreeChart chart = new JFreeChart(dataset.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); // chart = new JFreeChart(dataset.getTitle(), plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); PaintScale scaleBar = generateRainbowScale(min, max, StaticValues.DEFAULT_COLOR_SCALE); PaintScaleLegend legend = createScaleLegend(scale, scaleAxis); legend.setSubdivisionCount(ColorScale.DIVISION_COUNT); // legend.setStripOutlineVisible(true); chart.addSubtitle(legend); chart.setBorderVisible(true); // ChartUtilities.applyCurrentTheme(chart); chartTheme.apply(chart); chart.fireChartChanged(); return chart; }
From source file:org.jfree.chart.demo.XYBlockChartDemo1.java
private static JFreeChart createChart(XYZDataset xyzdataset) { NumberAxis numberaxis = new NumberAxis("X"); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setLowerMargin(0.0D);/*from ww w. j a v a 2s . com*/ numberaxis.setUpperMargin(0.0D); numberaxis.setAxisLinePaint(Color.white); numberaxis.setTickMarkPaint(Color.white); NumberAxis numberaxis1 = new NumberAxis("Y"); numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis1.setLowerMargin(0.0D); numberaxis1.setUpperMargin(0.0D); numberaxis1.setAxisLinePaint(Color.white); numberaxis1.setTickMarkPaint(Color.white); XYBlockRenderer xyblockrenderer = new XYBlockRenderer(); GrayPaintScale graypaintscale = new GrayPaintScale(-2D, 1.0D); xyblockrenderer.setPaintScale(graypaintscale); XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinesVisible(false); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setOutlinePaint(Color.blue); JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo1", xyplot); jfreechart.removeLegend(); NumberAxis numberaxis2 = new NumberAxis("Scale"); numberaxis2.setAxisLinePaint(Color.white); numberaxis2.setTickMarkPaint(Color.white); numberaxis2.setTickLabelFont(new Font("Dialog", 0, 7)); PaintScaleLegend paintscalelegend = new PaintScaleLegend(new GrayPaintScale(), numberaxis2); paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); paintscalelegend.setAxisOffset(5D); paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D)); paintscalelegend.setFrame(new BlockBorder(Color.red)); paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); paintscalelegend.setStripWidth(10D); paintscalelegend.setPosition(RectangleEdge.RIGHT); paintscalelegend.setBackgroundPaint(new Color(120, 120, 180)); jfreechart.addSubtitle(paintscalelegend); jfreechart.setBackgroundPaint(new Color(180, 180, 250)); return jfreechart; }