List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:eu.delving.stats.ChartHelper.java
private static JFreeChart createWordCountChart(Stats.ValueStats valueStats, Path path, String name) { if (valueStats.wordCounts == null) return null; List<Stats.Counter> sorted = sort(valueStats.wordCounts.counterMap.values(), MAX_BAR_CHART_SIZE, valueStats.total);//from w ww .j a va 2 s.c o m DefaultCategoryDataset data = new DefaultCategoryDataset(); for (Stats.Counter counter : sorted) data.addValue(counter.count, "Count", counter.value); JFreeChart chart = ChartFactory.createBarChart(String.format("Word count per occurrence in %s", name), "Number of Words", "Record count", data, PlotOrientation.VERTICAL, false, true, false); chart.addSubtitle(new TextTitle(path.toString())); return finishBarChart(chart, new Color(218, 112, 214)); }
From source file:com.greenpepper.confluence.macros.historic.AbstractChartBuilder.java
protected void addSubTitle(JFreeChart chart, String subTitle, Font font) { if (StringUtils.isNotEmpty(subTitle)) { TextTitle chartSubTitle = new TextTitle(subTitle); customizeTitle(chartSubTitle, font); chart.addSubtitle(chartSubTitle); }//from w w w. j av a 2 s . co m }
From source file:opensonata.dataDisplays.BaselineImage.java
private JFreeChart createChart(String inFilename, String userTitle, NssBaseline nssBaseline) { XYSeries series = new XYSeries(""); float[] baselineValues = nssBaseline.getBaselineValues(); // plot subband values for (int i = 0; i < baselineValues.length; i++) { series.add(i, baselineValues[i]); }/*from w w w.ja va 2 s . c o m*/ System.err.println("HERE!!!!"); // add a final point at the end with a zero Y value, series.add(baselineValues.length, 0.0); XYDataset data = new XYSeriesCollection(series); String inFilenameBase = new File(inFilename).getName(); DecimalFormat freqFormatter = new DecimalFormat("0000.000 MHz "); String freqString = freqFormatter.format(nssBaseline.getCenterFreqMhz()); DecimalFormat bandwidthFormatter = new DecimalFormat("0.00 MHz "); String bandwidthString = bandwidthFormatter.format(nssBaseline.getBandwidthMhz()); String mainTitle = ""; String xAxisLabel = "Subband"; String yAxisLabel = "Power"; JFreeChart chart = ChartFactory.createXYLineChart(mainTitle, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, false, // legend true, // tooltips false // urls ); String subTitle1 = "Baseline: "; if (!userTitle.equals("")) { subTitle1 += userTitle; } else { subTitle1 += inFilenameBase; } chart.addSubtitle(new TextTitle(subTitle1)); String subTitle2 = "Center Freq: " + freqString + "Bandwidth: " + bandwidthString; chart.addSubtitle(new TextTitle(subTitle2)); // move the data off of the axes // by extending the minimum axis value XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot(); double axisMarginPercent = 0.02; NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); valueAxis = (NumberAxis) plot.getDomainAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); return chart; }
From source file:org.jfree.experimental.chart.annotations.junit.XYTitleAnnotationTests.java
/** * Serialize an instance, restore it, and check for equality. *//*from w w w. j a va 2 s .c om*/ public void testSerialization() { TextTitle t = new TextTitle("Title"); XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); XYTitleAnnotation a2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(a1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); a2 = (XYTitleAnnotation) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(a1, a2); }
From source file:com.rcp.wbw.demo.editor.SWTTitleEditor.java
/** * Standard constructor: builds a panel for displaying/editing the * properties of the specified title./*from ww w. j a v a 2s .co m*/ * * @param parent * the parent. * @param style * the style. * @param title * the title, which should be changed. * */ SWTTitleEditor(Composite parent, int style, Title title) { super(parent, style); FillLayout layout = new FillLayout(); layout.marginHeight = layout.marginWidth = 4; setLayout(layout); TextTitle t = (title != null ? (TextTitle) title : new TextTitle(localizationResources.getString("Title"))); this.showTitle = (title != null); this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), true); this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint()); Group general = new Group(this, SWT.NONE); general.setLayout(new GridLayout(3, false)); general.setText(localizationResources.getString("General")); // row 1 Label label = new Label(general, SWT.NONE); label.setText(localizationResources.getString("Show_Title")); GridData gridData = new GridData(); gridData.horizontalSpan = 2; label.setLayoutData(gridData); this.showTitleCheckBox = new Button(general, SWT.CHECK); this.showTitleCheckBox.setSelection(this.showTitle); this.showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); this.showTitleCheckBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { SWTTitleEditor.this.showTitle = SWTTitleEditor.this.showTitleCheckBox.getSelection(); } }); // row 2 new Label(general, SWT.NONE).setText(localizationResources.getString("Text")); this.titleField = new Text(general, SWT.BORDER); this.titleField.setText(t.getText()); this.titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(general, SWT.NONE).setText(""); // row 3 new Label(general, SWT.NONE).setText(localizationResources.getString("Font")); this.fontField = new Text(general, SWT.BORDER); this.fontField.setText(this.titleFont.toString()); this.fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); this.selectFontButton = new Button(general, SWT.PUSH); this.selectFontButton.setText(localizationResources.getString("Select...")); this.selectFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the font-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTTitleEditor.this.titleFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTTitleEditor.this.font != null) { SWTTitleEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTTitleEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); // titleField.setFont(font); SWTTitleEditor.this.fontField.setText(SWTTitleEditor.this.font.getFontData()[0].toString()); SWTTitleEditor.this.titleFont = SWTTitleEditor.this.font.getFontData()[0]; } } }); // row 4 new Label(general, SWT.NONE).setText(localizationResources.getString("Color")); // Use a SwtPaintCanvas to show the color, note that we must set the // heightHint. final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.titleColor); GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); canvasGridData.heightHint = 20; colorCanvas.setLayoutData(canvasGridData); this.selectColorButton = new Button(general, SWT.PUSH); this.selectColorButton.setText(localizationResources.getString("Select...")); this.selectColorButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(getShell()); dlg.setText(localizationResources.getString("Title_Color")); dlg.setRGB(SWTTitleEditor.this.titleColor.getRGB()); RGB rgb = dlg.open(); if (rgb != null) { // create the new color and set it to the // SwtPaintCanvas SWTTitleEditor.this.titleColor = new Color(getDisplay(), rgb); colorCanvas.setColor(SWTTitleEditor.this.titleColor); } } }); }
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);/*from ww w .java2 s. co m*/ 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:sentimentanalyzer.ChartController.java
public void createAndPopulatePieChart__TESTER(JPanel pnlPieChart) { DefaultPieDataset data = new DefaultPieDataset(); data.setValue(Pos, 0 /*count for 1 */); data.setValue(Neu, 0 /*count for 0 */); data.setValue(Neg, 0 /*count for -1 */); JFreeChart chart = ChartFactory.createPieChart("Sent. Distr. for Testing", data, false, // legend? false, // tooltips? false // URLs? );/* ww w. ja v a 2 s . c o m*/ ChartPanel CP = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Pie chart is not available", Color.LIGHT_GRAY); plot.setExplodePercent(Pos, 0.025); plot.setExplodePercent(Neg, 0.025); plot.setExplodePercent(Neu, 0.025); //Customize PieChart to show absolute values and percentages; PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.00%")); plot.setLabelGenerator(gen); TextTitle legendText = new TextTitle("The total number of tweets: "); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); pnlPieChart.setLayout(new java.awt.BorderLayout()); pnlPieChart.add(CP, BorderLayout.CENTER); }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo1.java
/** * Creates a sample chart./*from w ww . jav a 2 s .com*/ * * @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:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java
public void setGraph() { if (hasGroupVariable) { DefaultCategoryDataset piedat = new DefaultCategoryDataset(); chart = ChartFactory.createMultiplePieChart(chartTitle, piedat, TableOrder.BY_ROW, showLegend, true, false);/*from w w w. j av a 2 s . com*/ if (chartSubtitle != null && !"".equals(chartSubtitle)) { TextTitle subtitle1 = new TextTitle(chartSubtitle); chart.addSubtitle(subtitle1); } MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot(); JFreeChart subchart = plot.getPieChart(); PiePlot p = (PiePlot) subchart.getPlot(); p.setBackgroundPaint(Color.WHITE); p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); if (explode) p.setExplodePercent(explodeValue, explodePercent); ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.add(panel); } else { DefaultPieDataset piedat = new DefaultPieDataset(); if (command.getSelectOneOption("view").isValueSelected("3D")) { chart = ChartFactory.createPieChart3D(chartTitle, piedat, showLegend, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); if (explode) plot.setExplodePercent(explodeValue, explodePercent); } else { chart = ChartFactory.createPieChart(command.getFreeOption("title").getString(), piedat, showLegend, true, false); } if (chartSubtitle != null && !"".equals(chartSubtitle)) { TextTitle subtitle = new TextTitle(chartSubtitle); chart.addSubtitle(subtitle); } PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGap(0.02); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); plot.setBackgroundPaint(Color.WHITE); if (explode) plot.setExplodePercent(explodeValue, explodePercent); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } }
From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java
public void setGraph() { HistogramChartDataset personDataset = null; HistogramChartDataset itemData = null; try {/*from w ww . j ava 2 s .c o m*/ //get titles String chartTitle = command.getFreeOption("title").getString(); String chartSubtitle = command.getFreeOption("subtitle").getString(); PlotOrientation itemMapOrientation = PlotOrientation.HORIZONTAL; //create common x-axis NumberAxis domainAxis = new NumberAxis(); domainAxis.setLabel("Logits"); //create histogram personDataset = new HistogramChartDataset(); ValueAxis rangeAxis = new NumberAxis("Person Density"); if (itemMapOrientation == PlotOrientation.HORIZONTAL) rangeAxis.setInverted(true); XYBarRenderer renderer = new XYBarRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setURLGenerator(new StandardXYURLGenerator()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); XYPlot personPlot = new XYPlot(personDataset, null, rangeAxis, renderer); personPlot.setOrientation(PlotOrientation.HORIZONTAL); //create scatterplot of item difficulty itemData = new HistogramChartDataset(); NumberAxis itemRangeAxis = new NumberAxis("Item Frequency"); if (itemMapOrientation == PlotOrientation.VERTICAL) { itemRangeAxis.setInverted(true); } XYBarRenderer itemRenderer = new XYBarRenderer(); itemRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); itemRenderer.setURLGenerator(new StandardXYURLGenerator()); itemRenderer.setDrawBarOutline(true); itemRenderer.setShadowVisible(false); XYPlot itemPlot = new XYPlot(itemData, null, itemRangeAxis, itemRenderer); itemPlot.setOrientation(PlotOrientation.HORIZONTAL); //combine the two charts CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(personPlot, 3); cplot.add(itemPlot, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); cplot.setOrientation(itemMapOrientation); // //next four lines are temp setting for book // //these four lines will create a histogram with white bars so it appears as just the bar outline // renderer.setBarPainter(new StandardXYBarPainter()); // renderer.setSeriesPaint(0, Color.white); // itemRenderer.setBarPainter(new StandardXYBarPainter()); // itemRenderer.setSeriesPaint(0, Color.white); chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); if (chartSubtitle != null && !"".equals(chartSubtitle)) { chart.addSubtitle(new TextTitle(chartSubtitle)); } ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); // //temp setting for book // this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }