List of usage examples for org.jfree.chart.title LegendTitle setPosition
public void setPosition(RectangleEdge position)
From source file:org.jfree.chart.demo.SpiderWebChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { SpiderWebPlot plot = new SpiderWebPlot(categorydataset); plot.setStartAngle(54D);// ww w . j av a2s .c o m plot.setInteriorGap(0.40000000000000002D); plot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); JFreeChart chart = new JFreeChart("Spider Web Chart Demo 1", TextTitle.DEFAULT_FONT, plot, false); LegendTitle legendtitle = new LegendTitle(plot); legendtitle.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendtitle); return chart; }
From source file:moviedatas.View.SpiderWebChart.java
/** * Creates a sample chart.// ww w . j ava 2 s .com * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { SpiderWebPlot plot = new SpiderWebPlot(dataset); plot.setStartAngle(54); plot.setInteriorGap(0.40); //plot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, false); LegendTitle legend = new LegendTitle(plot); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); //ChartUtilities.applyCurrentTheme(chart); return chart; }
From source file:org.jfree.chart.demo.StackedXYBarChartDemo2.java
private static JFreeChart createChart(TableXYDataset tablexydataset) { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D);// w w w .j a va 2s .com dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = new NumberAxis("Count"); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setUpperMargin(0.10000000000000001D); StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D); stackedxybarrenderer.setDrawBarOutline(false); stackedxybarrenderer.setBaseItemLabelsVisible(true); stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); stackedxybarrenderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0"))); XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer); JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot); jfreechart.removeLegend(); jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003")); TextTitle texttitle = new TextTitle( "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html", new Font("Dialog", 0, 8)); jfreechart.addSubtitle(texttitle); jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setBackgroundPaint(Color.white); legendtitle.setFrame(new BlockBorder()); legendtitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(legendtitle); return jfreechart; }
From source file:at.granul.mason.collector.ChartFileScalarDataWriter.java
public static void exportGraph(XYChartGenerator chart, String prefix, int width, int height) { try {//from w w w . j a v a2s . c o m Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(prefix + "_" + DataWriter.DF.format(new Date()) + ".pdf"))); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); //PdfTemplate tp = cb.createTemplate(width, height); //Write the chart with all datasets chart.addLegend(); /*LegendTitle title = new LegendTitle(chart.getChart().getPlot()); title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0,8,0,4)); chart.addLegend(title);*/ LegendTitle legendTitle = chart.getChart().getLegend(); legendTitle.setPosition(RectangleEdge.BOTTOM); Graphics2D g2 = cb.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); chart.getChart().draw(g2, rectangle2D); g2.dispose(); //PNG Output ChartUtilities.saveChartAsJPEG(new File(prefix + "_" + DataWriter.DF.format(new Date()) + ".png"), chart.getChart(), width, height); chart.getChart().removeLegend(); //tp = cb.createTemplate(width, height); //All invisible final XYItemRenderer renderer = chart.getChartPanel().getChart().getXYPlot().getRenderer(); for (int a = 0; a < chart.getSeriesCount(); a++) { renderer.setSeriesVisible(a, false); } final Dataset seriesDataset = chart.getSeriesDataset(); XYSeriesCollection series = ((XYSeriesCollection) seriesDataset); for (int a = 0; a < chart.getSeriesCount(); a++) { renderer.setSeriesVisible(a, true); final String seriesName = series.getSeries(a).getKey() + ""; chart.setYAxisLabel(seriesName); document.newPage(); g2 = cb.createGraphics(width, height * (a + 2), new DefaultFontMapper()); g2.translate(0, height * (a + 1)); chart.getChart().draw(g2, rectangle2D); g2.dispose(); //PNG Output ChartUtilities.saveChartAsJPEG( new File(prefix + "_" + seriesName + DataWriter.DF.format(new Date()) + ".png"), chart.getChart(), width, height); renderer.setSeriesVisible(a, false); } //cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jfree.chart.demo.XYTitleAnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, false, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setItemFont(new Font("Dialog", 0, 9)); legendtitle.setBackgroundPaint(new Color(200, 200, 255, 100)); legendtitle.setFrame(new BlockBorder(Color.white)); legendtitle.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.02D, legendtitle, RectangleAnchor.BOTTOM_RIGHT); xytitleannotation.setMaxWidth(0.47999999999999998D); xyplot.addAnnotation(xytitleannotation); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); }//from w w w . j a v a 2s .c om DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setLowerMargin(0.34999999999999998D); return jfreechart; }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) { final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset, PlotOrientation.VERTICAL, true, true, false); final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setNoDataMessage("NO DATA!"); chart.setBackgroundPaint(new Color(245, 245, 255)); chart.setBorderPaint(new Color(204, 204, 204)); chart.setBorderStroke(new BasicStroke(1f)); final LegendTitle legend = chart.getLegend(); legend.setWidth(1000);/*from w w w. j av a2 s . c om*/ legend.setPosition(RectangleEdge.BOTTOM); final BlockBorder border = new BlockBorder(new Color(204, 204, 204)); legend.setBorder(border); final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot(); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204)); categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setDrawBarOutline(true); final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); renderer.setPositiveItemLabelPosition(itemlabelposition); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); return chart; }
From source file:org.gaixie.micrite.jfreechart.style.PieStyle.java
/** * ?2???block/*from www . ja v a 2s. 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.tap4j.plugin.util.GraphHelper.java
public static JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedAreaChart("TAP Tests", // chart title null, // unused "TAP Tests Count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );//from www. ja va2 s . c o m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); StackedAreaRenderer ar = new StackedAreaRenderer2() { private static final long serialVersionUID = 331915263367089058L; @Override public String generateURL(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); return label.build.getNumber() + "/" + AbstractTapProjectAction.URL_NAME + "/"; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); TapBuildAction build = label.build.getAction(TapBuildAction.class); TapResult report = build.getResult(); report.tally(); switch (row) { case 0: return String.valueOf(report.getFailed()) + " Failure(s)"; case 1: return String.valueOf(report.getPassed()) + " Pass"; case 2: return String.valueOf(report.getSkipped()) + " Skip(s)"; default: return ""; } } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Failures ar.setSeriesPaint(1, ColorPalette.BLUE); // Pass ar.setSeriesPaint(2, ColorPalette.YELLOW); // Skips // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
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);/*ww w . j av a2 s .co m*/ 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); 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.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
/** * Creates a chart./*from w w w . ja v a2 s.c o m*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(200, 200, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, RectangleAnchor.BOTTOM_RIGHT); ta.setMaxWidth(0.48); plot.addAnnotation(ta); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setLowerMargin(0.35); return chart; }