List of usage examples for org.jfree.chart.title TextTitle setPosition
public void setPosition(RectangleEdge position)
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart/*from w w w. j av a 2 s . c om*/ */ public JFreeChart createWaferMapChartPositionIndexed() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(500); final WaferMapPlot plot = new WaferMapPlot(dataset); final WaferMapRenderer renderer = new WaferMapRenderer(35, WaferMapRenderer.POSITION_INDEX); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart("Wafer Map Demo - Position Indexed", JFreeChart.DEFAULT_TITLE_FONT, plot, true); // 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); return chart; }
From source file:com.tonbeller.jpivot.chart.ChartComponent.java
/** * Entry point for producing charts, called by wcf render tag. * Produces a jfreechart dataset from olap model, then creates a chart and * writes it to the servlet container temp directory. * Returns a DOM document for Renderer to transform into html. * Requires that jfreechart servlet is installed in this application context. *///from www .j a va 2s . co m public Document render(RequestContext context) throws Exception { // check if we need to produce a new chart if (dirty) { // clear old listeners dispatcher.clear(); this.result = olapModel.getResult(); this.cellIterator = result.getCells().iterator(); this.dimCount = result.getAxes().length; DefaultCategoryDataset dataset = null; switch (dimCount) { case 1: logger.info("1-dim data"); dataset = build1dimDataset(); break; case 2: logger.info("2-dim data"); dataset = build2dimDataset(); break; default: logger.error("less than 1 or more than 2 dimensions"); throw new IllegalArgumentException("ChartRenderer requires a 1 or 2 dimensional result"); } // re-set dirty flag dirty = false; // create font titleFont = new java.awt.Font(fontName, fontStyle, fontSize); CategoryURLGenerator urlGenerator = new jpivotCategoryURLGenerator(webControllerURL); // Create the chart object JFreeChart chart = null; switch (chartType) { case 1: chart = ChartFactory.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 2: chart = ChartFactory.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 3: chart = ChartFactory.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 4: chart = ChartFactory.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 5: chart = ChartFactory.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 6: chart = ChartFactory.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 7: chart = ChartFactory.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 8: chart = ChartFactory.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 9: chart = ChartFactory.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 10: chart = ChartFactory.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 11: chart = ChartFactory.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 12: chart = ChartFactory.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 13: chart = ChartFactory.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 14: chart = ChartFactory.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator); break; case 15: chart = ChartFactory.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_COLUMN, dataset, webControllerURL)); break; case 16: chart = ChartFactory.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_ROW, dataset, webControllerURL)); break; case 17: chart = ChartFactory.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_COLUMN, dataset, webControllerURL)); break; case 18: chart = ChartFactory.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend, showTooltips, drillThroughEnabled, new jpivotPieURLGenerator(TableOrder.BY_ROW, dataset, webControllerURL)); break; default: throw new Exception("An unknown Chart Type was requested"); } try { chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB)); java.awt.Font slicerFont = new java.awt.Font(slicerFontName, slicerFontStyle, slicerFontSize); java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize); java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize); java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize); Plot plot = chart.getPlot(); if (plot instanceof CategoryPlot) { CategoryPlot catPlot = (CategoryPlot) plot; catPlot.getDomainAxis().setLabelFont(axisFont); catPlot.getRangeAxis().setLabelFont(axisFont); catPlot.getDomainAxis().setTickLabelFont(axisTickFont); catPlot.getRangeAxis().setTickLabelFont(axisTickFont); catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f); double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate; CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions(); CategoryLabelPositions newp = new CategoryLabelPositions( oldp.getLabelPosition(RectangleEdge.TOP), new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f), oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT)); catPlot.getDomainAxis().setCategoryLabelPositions(newp); } else if (plot instanceof PiePlot3D) { PiePlot3D piePlot = (PiePlot3D) plot; //piePlot.setSectionLabelFont(axisFont); piePlot.setLabelFont(axisFont); //piePlot.setSeriesLabelFont(axisTickFont); //piePlot.setSectionLabelType(piePlot.NO_LABELS); piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE); piePlot.setForegroundAlpha(0.5f); piePlot.setNoDataMessage("No data to display"); } else if (plot instanceof PiePlot) { PiePlot piePlot = (PiePlot) plot; //piePlot.setSectionLabelFont(axisFont); //piePlot.setSeriesLabelFont(axisTickFont); piePlot.setLabelFont(axisFont); //piePlot.setSectionLabelType(piePlot.NO_LABELS); } LegendTitle legend = (LegendTitle) chart.getLegend(); if (legend != null) { legend.setItemFont(legendFont); /* RectangleAnchor legendRectAnchor=RectangleAnchor.BOTTOM; switch (legendPosition){ case 0: legendRectAnchor = RectangleAnchor.LEFT; break; case 1: legendRectAnchor = RectangleAnchor.TOP; break; case 2: legendRectAnchor = RectangleAnchor.RIGHT; break; case 3: legendRectAnchor = RectangleAnchor.BOTTOM; break; } legend.setLegendItemGraphicAnchor(legendRectAnchor); */ RectangleEdge legendRectEdge = RectangleEdge.BOTTOM; switch (legendPosition) { case 0: legendRectEdge = RectangleEdge.LEFT; break; case 1: legendRectEdge = RectangleEdge.TOP; break; case 2: legendRectEdge = RectangleEdge.RIGHT; break; case 3: legendRectEdge = RectangleEdge.BOTTOM; break; } legend.setPosition(legendRectEdge); } if (showSlicer) { RectangleEdge slicerRectPos = RectangleEdge.BOTTOM; HorizontalAlignment slicerHorizAlignment = HorizontalAlignment.LEFT; switch (slicerPosition) { case 0: slicerRectPos = RectangleEdge.TOP; break; case 1: slicerRectPos = RectangleEdge.BOTTOM; break; case 2: slicerRectPos = RectangleEdge.RIGHT; break; case 3: slicerRectPos = RectangleEdge.LEFT; break; } switch (slicerAlignment) { case 4: slicerHorizAlignment = HorizontalAlignment.CENTER; break; case 3: slicerHorizAlignment = HorizontalAlignment.LEFT; break; case 2: slicerHorizAlignment = HorizontalAlignment.RIGHT; break; } TextTitle slicer = new TextTitle(buildSlicer(), slicerFont, Color.BLACK, slicerRectPos, slicerHorizAlignment, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); slicer.setPosition(slicerRectPos); chart.addSubtitle(slicer); } info = new ChartRenderingInfo(new StandardEntityCollection()); // Write the chart image to the temporary directory HttpSession session = context.getSession(); filename = ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, info, session); } catch (Exception e) { filename = "public_error_500x300.png"; dirty = true; } } // new DOM document DocumentBuilder parser = XmlUtils.getParser(); // get an image map for the chart, wrap it in xchart tags String xchart = "<xchart>" + writeImageMap(filename, info, false) + "</xchart>"; /* if (logger.isDebugEnabled()) { logger.debug("Chart XML"); logger.debug(xchart); } */ // create an InputStream from the DOM document InputStream stream = new ByteArrayInputStream(xchart.getBytes("UTF-8")); document = parser.parse(stream); Element root = document.getDocumentElement(); // create url for img tag String graphURL = getGraphURL(context); Element img = document.createElement("img"); img.setAttribute("src", graphURL); img.setAttribute("width", new Integer(chartWidth).toString()); img.setAttribute("height", new Integer(chartHeight).toString()); img.setAttribute("style", "border:0;"); img.setAttribute("usemap", "#" + filename); root.appendChild(img); return document; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *///from www.jav a 2 s . co m protected void configureChart(JFreeChart jfreeChart) throws JRException { if (getChart().getModeValue() == ModeEnum.OPAQUE) { jfreeChart.setBackgroundPaint(getChart().getBackcolor()); } else { jfreeChart.setBackgroundPaint(null); } RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP); if (jfreeChart.getTitle() != null) { TextTitle title = jfreeChart.getTitle(); title.setPaint(getChart().getTitleColor()); title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale())); title.setPosition(titleEdge); } String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setPaint(getChart().getSubtitleColor()); subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale())); subtitle.setPosition(titleEdge); jfreeChart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { legend.setItemPaint(getChart().getLegendColor()); if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless { legend.setBackgroundPaint(null); } else { legend.setBackgroundPaint(getChart().getLegendBackgroundColor()); } legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale())); legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM)); } configurePlot(jfreeChart.getPlot()); }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private void setTitle(JFreeChart chart, String title, Font titleFont, Color foregroundColor, List<cfCHARTTITLEData> titles) throws cfmRunTimeException { if (titles.size() > 0) { // One or more CFCHARTTITLE tags were specified so use them to configure // the chart titles for (int i = 0; i < titles.size(); i++) { cfCHARTTITLEData data = titles.get(i); Font font = getFont(data.getFont(), data.getFontBold(), data.getFontItalic(), data.getFontSize()); TextTitle textTitle = new TextTitle(data.getTitle(), font); textTitle.setPaint(convertStringToColor(data.getLabelColor())); textTitle.setBackgroundPaint(convertStringToColor(data.getBackgroundColor())); String pos = data.getPosition(); if (pos.equals("top")) textTitle.setPosition(RectangleEdge.TOP); else if (pos.equals("bottom")) textTitle.setPosition(RectangleEdge.BOTTOM); else if (pos.equals("left")) textTitle.setPosition(RectangleEdge.LEFT); else if (pos.equals("right")) textTitle.setPosition(RectangleEdge.RIGHT); if (!data.getShowBorder()) textTitle.setBorder(BlockBorder.NONE); else//from w w w . j a va2 s. com textTitle.setBorder(new BlockBorder()); textTitle.setPadding(data.getPadding(), data.getPadding(), data.getPadding(), data.getPadding()); textTitle.setMargin(data.getMargin(), data.getMargin(), data.getMargin(), data.getMargin()); chart.addSubtitle(textTitle); } } else { // A CFCHARTTITLE tag was NOT specified so use the CFCHART attributes to // configure the chart title if (title == null) return; TextTitle textTitle = new TextTitle(title, titleFont); textTitle.setPaint(foregroundColor); // Add a border around the title to match CFMX 7 textTitle.setBorder(new BlockBorder()); textTitle.setPadding(10, 10, 10, 10); textTitle.setMargin(5, 5, 5, 5); chart.setTitle(textTitle); } }
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);/*from w w w. j a va 2s. co m*/ if (titleForegroundPaint != null) title.setPaint(titleForegroundPaint); Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint() : null; 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);/*w w w .jav a2 s. c o m*/ if (titleForegroundPaint != null) title.setPaint(titleForegroundPaint); Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint() : null; if (backPaint != null) title.setBackgroundPaint(backPaint); if (titleEdge != null) title.setPosition(titleEdge); }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setChartTitle(JFreeChart jfreeChart, Integer baseFontSize) { Boolean titleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_VISIBLE); if (titleVisibility != null && titleVisibility.booleanValue()) { TextTitle title = jfreeChart.getTitle(); RectangleEdge titleEdge = null;/*w w w .java2 s. co m*/ if (title != null) { JRFont titleFont = getChart().getTitleFont(); Font themeTitleFont = getFont( (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FONT), titleFont, baseFontSize); title.setFont(themeTitleFont); HorizontalAlignment defaultTitleHAlignment = (HorizontalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.TITLE_HORIZONTAL_ALIGNMENT); if (defaultTitleHAlignment != null) title.setHorizontalAlignment(defaultTitleHAlignment); VerticalAlignment defaultTitleVAlignment = (VerticalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.TITLE_VERTICAL_ALIGNMENT); if (defaultTitleVAlignment != null) title.setVerticalAlignment(defaultTitleVAlignment); RectangleInsets defaultTitlePadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_PADDING); RectangleInsets titlePadding = title.getPadding() != null ? title.getPadding() : defaultTitlePadding; if (titlePadding != null) title.setPadding(titlePadding); Color titleForecolor = getChart().getOwnTitleColor() != null ? getChart().getOwnTitleColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) : getChart().getTitleColor()); if (titleForecolor != null) title.setPaint(titleForecolor); Color titleBackcolor = (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_BACKCOLOR); if (titleBackcolor != null) title.setBackgroundPaint(titleBackcolor); RectangleEdge defaultTitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_POSITION); titleEdge = getEdge(getChart().getTitlePositionValue(), defaultTitlePosition); if (titleEdge != null) title.setPosition(titleEdge); } } else { TextTitle title = null; jfreeChart.setTitle(title); } }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected void setChartTitle(JFreeChart jfreeChart, Integer baseFontSize) { Boolean titleVisibility = (Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_VISIBLE); if (titleVisibility != null && titleVisibility) { TextTitle title = jfreeChart.getTitle(); RectangleEdge titleEdge = null;//from ww w .ja v a2 s. c o m if (title != null) { JRFont titleFont = getChart().getTitleFont(); Font themeTitleFont = getFont( (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FONT), titleFont, baseFontSize); title.setFont(themeTitleFont); HorizontalAlignment defaultTitleHAlignment = (HorizontalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.TITLE_HORIZONTAL_ALIGNMENT); if (defaultTitleHAlignment != null) title.setHorizontalAlignment(defaultTitleHAlignment); VerticalAlignment defaultTitleVAlignment = (VerticalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.TITLE_VERTICAL_ALIGNMENT); if (defaultTitleVAlignment != null) title.setVerticalAlignment(defaultTitleVAlignment); RectangleInsets defaultTitlePadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_PADDING); RectangleInsets titlePadding = title.getPadding() != null ? title.getPadding() : defaultTitlePadding; if (titlePadding != null) title.setPadding(titlePadding); Color titleForecolor = getChart().getOwnTitleColor() != null ? getChart().getOwnTitleColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_FORECOLOR) : getChart().getTitleColor()); if (titleForecolor != null) title.setPaint(titleForecolor); Color titleBackcolor = (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_BACKCOLOR); if (titleBackcolor != null) title.setBackgroundPaint(titleBackcolor); RectangleEdge defaultTitlePosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.TITLE_POSITION); titleEdge = getEdge(getChart().getTitlePositionValue(), defaultTitlePosition); if (titleEdge != null) title.setPosition(titleEdge); } } else { TextTitle title = null; jfreeChart.setTitle(title); } }
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;/*from www . j a v a2 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); } } }
From source file:net.sf.jasperreports.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) { String subtitleText = evaluateTextExpression(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 av a 2 s. c o m 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); } } }