List of usage examples for org.jfree.chart.title TextTitle setPadding
public void setPadding(RectangleInsets padding)
From source file:net.nosleep.superanalyzer.panels.HomePanel.java
public static TextTitle createSubtitle(String s) { TextTitle subtitle = new TextTitle(s); subtitle.setPosition(RectangleEdge.TOP); subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); return subtitle; }
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);/*from ww w . ja va 2 s .com*/ 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); 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:edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1.java
/** * Creates a Area chart./*www . jav a 2 s . co m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createAreaChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); if (isDemo) { TextTitle subtitle = 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."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); subtitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AreaRenderer renderer = (AreaRenderer) plot.getRenderer(); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); if (isDemo) { domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); } NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); return chart; }
From source file:org.n52.io.measurement.img.ChartIoHandler.java
private void addNotice(JFreeChart chart) { TextTitle notice = new TextTitle(); String msg = i18n.get("msg.io.chart.notice"); if (msg != null && !msg.isEmpty()) { notice.setText(msg);//from w w w . j ava2s.c o m notice.setPaint(BLACK); notice.setFont(FONT_LABEL_SMALL); notice.setPosition(RectangleEdge.BOTTOM); notice.setHorizontalAlignment(HorizontalAlignment.RIGHT); notice.setVerticalAlignment(VerticalAlignment.BOTTOM); notice.setPadding(new RectangleInsets(0, 0, 20, 20)); chart.addSubtitle(notice); } }
From source file:org.n52.io.type.quantity.handler.img.ChartIoHandler.java
private void addNotice(JFreeChart chart) { TextTitle notice = new TextTitle(); String msg = i18n.get("msg.io.chart.notice"); if (msg != null && !msg.isEmpty()) { notice.setText(msg);//ww w .j av a 2 s .c om notice.setPaint(Color.BLACK); notice.setFont(LabelConstants.FONT_LABEL_SMALL); notice.setPosition(RectangleEdge.BOTTOM); notice.setHorizontalAlignment(HorizontalAlignment.RIGHT); notice.setVerticalAlignment(VerticalAlignment.BOTTOM); notice.setPadding(new RectangleInsets(0, 0, 20, 20)); chart.addSubtitle(notice); } }
From source file:org.toobsframework.pres.chart.ChartBuilder.java
private JFreeChart finishChart(IRequest componentRequest, ChartDefinition chartDef, Plot plot, Map params) { JFreeChart chart = new JFreeChart( ChartUtil.evaluateTextLabel(componentRequest, chartDef.getTitle(), params), ChartUtil.getFont(chartDef.getTitle(), JFreeChart.DEFAULT_TITLE_FONT), plot, chartDef.isShowLegend());//from w ww . j av a 2s. c om if (chartDef.getSubtitle() != null) { TextTitle subtitle = new TextTitle( ChartUtil.evaluateTextLabel(componentRequest, chartDef.getSubtitle(), params)); if (chartDef.getSubtitle().getFont() != null) { subtitle.setFont(ChartUtil.getFont(chartDef.getSubtitle(), null)); } subtitle.setPosition(ChartUtil.getPosition(chartDef.getSubtitle().getPosition())); subtitle.setPadding( ChartUtil.getRectangle(componentRequest, chartDef.getSubtitle().getPadding(), params)); subtitle.setVerticalAlignment( ChartUtil.getVerticalAlignment(chartDef.getSubtitle().getVerticalAlignment())); subtitle.setPaint(ChartUtil.getColor(chartDef.getSubtitle().getColor())); chart.addSubtitle(subtitle); } chart.setBackgroundPaint(ChartUtil.getColor(chartDef.getBackgroundColor())); if (chartDef.getTitle() != null && chartDef.getTitle().getColor() != null) { chart.getTitle().setPaint(ChartUtil.getColor(chartDef.getTitle().getColor())); } if (chartDef.isShowLegend()) { ChartUtil.configureLegend(componentRequest, chart, chartDef.getLegend(), params); } return chart; }
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.j av a 2s . c om 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:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void handleTitleSettings(TextTitle title, TitleSettings titleSettings, JRFont titleFont, Paint titleForegroundPaint, RectangleEdge titleEdge) { JRBaseFont font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(titleSettings.getFont(), font); JRFontUtil.copyNonNullOwnProperties(titleFont, font); font = new JRBaseFont(getChart(), font); title.setFont(JRFontUtil.getAwtFont(font, getLocale())); HorizontalAlignment hAlign = titleSettings.getHorizontalAlignment(); if (hAlign != null) title.setHorizontalAlignment(hAlign); VerticalAlignment vAlign = titleSettings.getVerticalAlignment(); if (vAlign != null) title.setVerticalAlignment(vAlign); RectangleInsets padding = titleSettings.getPadding(); if (padding != null) title.setPadding(padding); if (titleForegroundPaint != null) title.setPaint(titleForegroundPaint); Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint() : null;//from w w w . j a va 2 s . com if (backPaint != null) title.setBackgroundPaint(backPaint); if (titleEdge != null) title.setPosition(titleEdge); }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected void handleTitleSettings(TextTitle title, TitleSettings titleSettings, JRFont titleFont, Paint titleForegroundPaint, RectangleEdge titleEdge) { JRBaseFont font = new JRBaseFont(); FontUtil.copyNonNullOwnProperties(titleSettings.getFont(), font); FontUtil.copyNonNullOwnProperties(titleFont, font); font = new JRBaseFont(getChart(), font); title.setFont(getFontUtil().getAwtFont(font, getLocale())); HorizontalAlignment hAlign = titleSettings.getHorizontalAlignment(); if (hAlign != null) title.setHorizontalAlignment(hAlign); VerticalAlignment vAlign = titleSettings.getVerticalAlignment(); if (vAlign != null) title.setVerticalAlignment(vAlign); RectangleInsets padding = titleSettings.getPadding(); if (padding != null) title.setPadding(padding); if (titleForegroundPaint != null) title.setPaint(titleForegroundPaint); Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint() : null;/*w w w . ja va 2 s. c o m*/ if (backPaint != null) title.setBackgroundPaint(backPaint); if (titleEdge != null) title.setPosition(titleEdge); }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setChartSubtitles(JFreeChart jfreeChart, Integer baseFontSize) throws JRException { Boolean subtitleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VISIBLE); if (subtitleVisibility != null && subtitleVisibility.booleanValue()) { String subtitleText = (String) evaluateExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); Font themeSubtitleFont = getFont( (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FONT), getChart().getSubtitleFont(), baseFontSize); subtitle.setFont(themeSubtitleFont); HorizontalAlignment defaultSubtitleHAlignment = (HorizontalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_HORIZONTAL_ALIGNMENT); if (defaultSubtitleHAlignment != null) subtitle.setHorizontalAlignment(defaultSubtitleHAlignment); VerticalAlignment defaultSubtitleVAlignment = (VerticalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_VERTICAL_ALIGNMENT); if (defaultSubtitleVAlignment != null) subtitle.setVerticalAlignment(defaultSubtitleVAlignment); RectangleInsets defaultSubtitlePadding = (RectangleInsets) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_PADDING); RectangleInsets subtitlePadding = subtitle.getPadding() != null ? subtitle.getPadding() : defaultSubtitlePadding; if (subtitlePadding != null) subtitle.setPadding(subtitlePadding); Color subtitleForecolor = getChart().getOwnSubtitleColor() != null ? getChart().getOwnSubtitleColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FORECOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_FORECOLOR) : getChart().getSubtitleColor()); if (subtitleForecolor != null) subtitle.setPaint(subtitleForecolor); Color subtitleBackcolor = getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_BACKCOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_BACKCOLOR) : null;/* w ww . j a v a 2 s .com*/ if (subtitleBackcolor != null) subtitle.setBackgroundPaint(subtitleBackcolor); RectangleEdge defaultSubtitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.SUBTITLE_POSITION); //Subtitle has not its own position set, and by default this will be set the same as title position RectangleEdge subtitleEdge = null; if (defaultSubtitlePosition == null) { subtitleEdge = jfreeChart.getTitle().getPosition(); } else { subtitleEdge = defaultSubtitlePosition; } if (subtitleEdge != null) subtitle.setPosition(subtitleEdge); jfreeChart.addSubtitle(subtitle); } } }