List of usage examples for org.jfree.chart.title TextTitle setHorizontalAlignment
public void setHorizontalAlignment(HorizontalAlignment alignment)
From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java
public static void customizeTitle(TextTitle title, ChartParams params, String prefix) { if (params.get(prefix + ChartParams.TITLE_FONT_SUFFIX) != null) { title.setFont(params.getFont(prefix + ChartParams.TITLE_FONT_SUFFIX)); } else {//from w w w . ja v a 2 s . co m title.setFont(JFreeChart.DEFAULT_TITLE_FONT); } if (params.get(prefix + ChartParams.TITLE_POSITION_SUFFIX) != null) { title.setPosition(params.getRectangleEdge(prefix + ChartParams.TITLE_POSITION_SUFFIX)); } if (params.get(prefix + ChartParams.TITLE_HORIZONTAL_ALIGNMENT_SUFFIX) != null) { title.setHorizontalAlignment( params.getHorizontalAlignment(prefix + ChartParams.TITLE_HORIZONTAL_ALIGNMENT_SUFFIX)); } if (params.get(prefix + ChartParams.TITLE_VERTICAL_ALIGNMENT_SUFFIX) != null) { title.setVerticalAlignment( params.getVerticalAlignment(prefix + ChartParams.TITLE_VERTICAL_ALIGNMENT_SUFFIX)); } if (params.get(prefix + ChartParams.TITLE_COLOR_SUFFIX) != null) { title.setPaint(params.getColor(prefix + ChartParams.TITLE_COLOR_SUFFIX)); } if (params.get(prefix + ChartParams.TITLE_BACKGROUND_COLOR_SUFFIX) != null) { title.setBackgroundPaint(params.getColor(prefix + ChartParams.TITLE_BACKGROUND_COLOR_SUFFIX)); } if (params.get(prefix + ChartParams.TITLE_PADDING_SUFFIX) != null) { title.setPadding(params.getRectangleInsets(prefix + ChartParams.TITLE_PADDING_SUFFIX)); } if (params.get(prefix + ChartParams.TITLE_URL_SUFFIX) != null) { title.setURLText(params.getString(prefix + ChartParams.TITLE_URL_SUFFIX)); } }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//from w ww .j a v a 2s .co m * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // no legend true, // tooltips false // no URL generation ); // set a custom background for the chart 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); // use gradients and white borders for the section colours int itemIndex = 0; for (Object col : pieDataset.getKeys()) { plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]); if (itemIndex == pieDataset.getItemCount() - 1) { itemIndex = 0; } itemIndex++; } plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); 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.jfree.chart.demo.WaferMapChartDemo.java
/** * Creates a new demo./*from w w w . j a v a 2 s .c om*/ * * @param title the frame title. */ public WaferMapChartDemo(final String title) { super(title); final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(5); final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo", // title dataset, // wafermapdataset PlotOrientation.VERTICAL, // vertical = notchdown true, // legend false, // tooltips false); // final Legend legend = chart.getLegend(); // legend.setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 400)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.SurveyResultsDemo2.java
/** * Creates a chart.// ww w .j a va2s . c om * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.getPlot().setOutlinePaint(null); final TextTitle title = new TextTitle("Figure 8.5 - Case studies are available"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = chart.getCategoryPlot(); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(0.0, 5.0); rangeAxis.setVisible(false); final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null); domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); domainAxis.setCategoryMargin(0.30); domainAxis.addSubLabel("Sm.", "(10)"); domainAxis.addSubLabel("Med.", "(10)"); domainAxis.addSubLabel("Lg.", "(10)"); domainAxis.addSubLabel("All", "(10)"); plot.setDomainAxis(domainAxis); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER); renderer.setPositiveItemLabelPosition(position); renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition()); return chart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo3.java
/** * Creates a chart.//from w w w . j ava 2 s . c om * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.getPlot().setOutlinePaint(null); final TextTitle title = new TextTitle("Figure 6 | Overall SEO Rating"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = chart.getCategoryPlot(); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(0.0, 4.0); rangeAxis.setVisible(false); final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null); domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12)); domainAxis.setCategoryMargin(0.30); domainAxis.addSubLabel("Sm.", "(10)"); domainAxis.addSubLabel("Med.", "(10)"); domainAxis.addSubLabel("Lg.", "(10)"); domainAxis.addSubLabel("All", "(10)"); final CategoryLabelPositions p = domainAxis.getCategoryLabelPositions(); final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left)); plot.setDomainAxis(domainAxis); final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setBaseOutlineStroke(null); // final StandardCategoryLabelGenerator generator = new StandardCategoryLabelGenerator( // "{2}", new DecimalFormat("0.00") // ); // renderer.setLabelGenerator(generator); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition()); return chart; }
From source file:net.sf.statcvs.output.xml.chart.AbstractChart.java
/** * create chart with titles and credit information *//*from w w w .j a v a 2s . c om*/ public void placeTitle() { Font font = new Font("SansSerif", Font.PLAIN, 12); Font creditInformationFont = new Font("SansSerif", Font.PLAIN, 9); TextTitle title = new TextTitle(this.title, font); title.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0)); chart.addSubtitle(title); if (Settings.getShowCreditInformation()) { TextTitle copyright = new TextTitle("generated by statcvs-xml", creditInformationFont); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); } chart.setBackgroundPaint(Color.white); }
From source file:de.berlios.statcvs.xml.chart.AbstractChart.java
/** * create chart with titles and credit information *///www . ja v a 2s .co m protected void setup(boolean defaultShowLegend) { if (chart == null) { throw new NullPointerException("Chart is not initialized"); } if (this.subtitle != null && settings.getBoolean("showSubtitle", true)) { Font font = new Font("SansSerif", Font.PLAIN, 12); TextTitle title = new TextTitle(this.subtitle, font); title.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.0)); chart.addSubtitle(title); } if (settings.getBoolean("showCredit", true)) { Font font = new Font("SansSerif", Font.PLAIN, 9); TextTitle copyright = new TextTitle("generated by statcvs-xml\u00B2", font); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); } if (!settings.getBoolean("showLegend", defaultShowLegend)) { chart.setLegend(null); } chart.setBackgroundPaint(Color.white); }
From source file:sanger.team16.gui.genevar.eqtl.query.SNPGeneAssocPlot.java
public SNPGeneAssocPlot(List<Tuple> tuples, double max, double min) throws ArrayIndexOutOfBoundsException { JPanel mainPanel = new JPanel(new GridLayout(0, 3)); mainPanel.setBackground(Color.white); int size = tuples.size(); for (int i = 0; i < size; i++) { Tuple tuple = tuples.get(i);//from w w w . j a v a 2s .c om String populationName = tuple.populationName; // if (trait.expressionRanks != null) { // BUG FIXED 02/02/10 if (tuple.phenotypes != null && tuple.phenotypes.length != 0) { CategoryDataset dataset = this.createDataset(tuple); JFreeChart chart = createChart(populationName, dataset, max, min); chart.setBackgroundPaint(Color.white); TextTitle textTitle = new TextTitle(tuple.subtitle); textTitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); //subtitle1.setPosition(RectangleEdge.BOTTOM); textTitle.setHorizontalAlignment(HorizontalAlignment.CENTER); chart.addSubtitle(textTitle); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(this.getAutoPreferredSize()); // Original Dimension(680, 420) mainPanel.add(chartPanel); } else { BaseJPane empty = new BaseJPane(2, 50, 0, 0); empty.setPreferredSize(this.getAutoPreferredSize()); BaseJPane na = new BaseJPane(); na.setLayout(new BorderLayout()); JLabel name = new JLabel(" " + populationName); name.setFont(new Font("Arial", Font.BOLD, 12)); name.setForeground(Color.gray); na.add(name, BorderLayout.PAGE_START); JLabel message = new JLabel("Not Available"); message.setForeground(Color.lightGray); na.add(message, BorderLayout.CENTER); empty.add(Box.createHorizontalGlue()); empty.add(na); empty.add(Box.createHorizontalGlue()); empty.setBaseSpringBox(); mainPanel.add(empty); } } this.add(mainPanel); }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo1.java
/** * Creates a sample chart./*from w w w . ja v a 2 s.c om*/ * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { if (isDemo) { chartTitle = "Java Standard Class Library"; domainLabel = "Release"; rangeLabel = "Class Count"; } else chartTitle = "Line Chart"; // create the chart... JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); if (isDemo) { chart.addSubtitle(new TextTitle("Number of Classes By Release")); TextTitle source = new TextTitle( "Source: Java In A Nutshell (4th Edition) " + "by David Flanagan (O'Reilly)"); source.setFont(new Font("SansSerif", Font.PLAIN, 10)); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); } else { chart.clearSubtitles(); } chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:org.jfree.chart.demo.SurveyResultsDemo.java
/** * Creates a chart.//from w ww .j av a 2s . co m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); final TextTitle title = new TextTitle("Figure 7 | I. Resources - The site offers users relevant, " + "informative and educational resources"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setOutlinePaint(null); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePosition(CategoryAnchor.END); plot.setDomainGridlineStroke(new BasicStroke(0.5f)); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinesVisible(false); plot.clearRangeMarkers(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setCategoryMargin(0.50); plot.getRangeAxis().setVisible(false); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setOutlineStroke(null); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.BOLD, 10)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); final CategoryTextAnnotation a1 = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0); a1.setFont(new Font("SansSerif", Font.BOLD, 12)); a1.setTextAnchor(TextAnchor.BOTTOM_LEFT); a1.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a1); final CategoryTextAnnotation a2 = new CategoryTextAnnotation( "2. White papers enhance users " + "understanding of the firm and its expertise.", "Category 2", 0.0); a2.setFont(new Font("SansSerif", Font.PLAIN, 12)); a2.setTextAnchor(TextAnchor.BOTTOM_LEFT); a2.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a2); final CategoryTextAnnotation a3 = new CategoryTextAnnotation( "3. White papers are relevant to " + "the firm's prospects and clients.", "Category 3", 0.0); a3.setFont(new Font("SansSerif", Font.PLAIN, 12)); a3.setTextAnchor(TextAnchor.BOTTOM_LEFT); a3.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a3); final CategoryTextAnnotation a4 = new CategoryTextAnnotation( "4. White papers are relevant to " + "the firm's positioning.", "Category 4", 0.0); a4.setFont(new Font("SansSerif", Font.PLAIN, 12)); a4.setTextAnchor(TextAnchor.BOTTOM_LEFT); a4.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a4); final CategoryTextAnnotation a5 = new CategoryTextAnnotation("5. Case studies are available.", "Category 5", 0.0); a5.setFont(new Font("SansSerif", Font.BOLD, 12)); a5.setTextAnchor(TextAnchor.BOTTOM_LEFT); a5.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a5); final CategoryTextAnnotation a6 = new CategoryTextAnnotation( "6. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 6", 0.0); a6.setFont(new Font("SansSerif", Font.PLAIN, 12)); a6.setTextAnchor(TextAnchor.BOTTOM_LEFT); a6.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a6); final CategoryTextAnnotation a7 = new CategoryTextAnnotation( "7. Case studies are relevant to " + "the firm's prospects and clients.", "Category 7", 0.0); a7.setFont(new Font("SansSerif", Font.PLAIN, 12)); a7.setTextAnchor(TextAnchor.BOTTOM_LEFT); a7.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a7); final CategoryTextAnnotation a8 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0); a8.setFont(new Font("SansSerif", Font.PLAIN, 12)); a8.setTextAnchor(TextAnchor.BOTTOM_LEFT); a8.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a8); final CategoryTextAnnotation a9 = new CategoryTextAnnotation("9. Case studies are available.", "Category 9", 0.0); a9.setFont(new Font("SansSerif", Font.BOLD, 12)); a9.setTextAnchor(TextAnchor.BOTTOM_LEFT); a9.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a9); final CategoryTextAnnotation a10 = new CategoryTextAnnotation( "10. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 10", 0.0); a10.setFont(new Font("SansSerif", Font.PLAIN, 12)); a10.setTextAnchor(TextAnchor.BOTTOM_LEFT); a10.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a10); final CategoryTextAnnotation a11 = new CategoryTextAnnotation( "11. Case studies are relevant " + "to the firm's prospects and clients.", "Category 11", 0.0); a11.setFont(new Font("SansSerif", Font.PLAIN, 12)); a11.setTextAnchor(TextAnchor.BOTTOM_LEFT); a11.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a11); final CategoryTextAnnotation a12 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0); a12.setFont(new Font("SansSerif", Font.PLAIN, 12)); a12.setTextAnchor(TextAnchor.BOTTOM_LEFT); a12.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a12); final CategoryTextAnnotation a13 = new CategoryTextAnnotation( "13. Users can easily access " + "resources based on viewer interest.", "Category 13", 0.0); a13.setFont(new Font("SansSerif", Font.BOLD, 12)); a13.setTextAnchor(TextAnchor.BOTTOM_LEFT); a13.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a13); final CategoryTextAnnotation a14 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant " + "information.", "Category 14", 0.0); a14.setFont(new Font("SansSerif", Font.BOLD, 12)); a14.setTextAnchor(TextAnchor.BOTTOM_LEFT); a14.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a14); final CategoryTextAnnotation a15 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0); a15.setFont(new Font("SansSerif", Font.BOLD, 12)); a15.setTextAnchor(TextAnchor.BOTTOM_LEFT); a15.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a15); return chart; }