List of usage examples for org.jfree.chart JFreeChart setBorderVisible
public void setBorderVisible(boolean visible)
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private JFreeChart renderXYChart(cfSession _Session, cfCHARTInternalData chartData, String tipStyle, String drillDownUrl, String seriesPlacement, int height) throws cfmRunTimeException { List<cfCHARTSERIESData> series = chartData.getSeries(); if (seriesPlacement.equals("stacked") || seriesPlacement.equals("percent")) throw newRunTimeException( "A chart with an xAxisType of 'scale' cannot be displayed with a seriesPlacement of '" + seriesPlacement + "'"); // Retrieve the attributes of the chart String backgroundColorStr = getDynamic(_Session, "BACKGROUNDCOLOR").toString(); Color backgroundColor = convertStringToColor(backgroundColorStr); String dataBackgroundColorStr = getDynamic(_Session, "DATABACKGROUNDCOLOR").toString(); Color dataBackgroundColor = convertStringToColor(dataBackgroundColorStr); String foregroundColorStr = getDynamic(_Session, "FOREGROUNDCOLOR").toString(); Color foregroundColor = convertStringToColor(foregroundColorStr); String labelFormat = getDynamic(_Session, "LABELFORMAT").toString().toLowerCase(); if (!labelFormat.equals("number") && !labelFormat.equals("currency") && !labelFormat.equals("percent") && !labelFormat.equals("date")) throw newRunTimeException("The labelFormat value '" + labelFormat + "' is not supported"); String xAxisTitle = null;//from ww w . ja va2 s . co m if (containsAttribute("XAXISTITLE")) xAxisTitle = getDynamic(_Session, "XAXISTITLE").toString(); String yAxisTitle = null; if (containsAttribute("YAXISTITLE")) yAxisTitle = getDynamic(_Session, "YAXISTITLE").toString(); String title = null; if (containsAttribute("TITLE")) title = getDynamic(_Session, "TITLE").toString(); Font font = getFont(_Session); int yAxisUnits = 0; if (containsAttribute("YAXISUNITS")) { if (containsAttribute("GRIDLINES")) throw newRunTimeException("You cannot specify both yAxisUnits and gridLines"); yAxisUnits = getDynamic(_Session, "YAXISUNITS").getInt(); if (yAxisUnits < 0) throw newRunTimeException("You must specify a positive value for yAxisUnits"); } int gridLines = -1; if (containsAttribute("GRIDLINES")) { gridLines = getDynamic(_Session, "GRIDLINES").getInt(); if (gridLines < 2) throw newRunTimeException("You must specify a value greater than 1 for gridLines"); } int markerSize = getDynamic(_Session, "MARKERSIZE").getInt(); int xOffset = getDynamic(_Session, "XOFFSET").getInt(); if (xOffset < 0) throw newRunTimeException("You must specify a positive value for xOffset"); double xUpperMargin = getDynamic(_Session, "XAXISUPPERMARGIN").getDouble(); if (xUpperMargin < 0) throw newRunTimeException("You must specify a positive value for xAxisUpperMargin"); int yOffset = getDynamic(_Session, "YOFFSET").getInt(); if (yOffset < 0) throw newRunTimeException("You must specify a positive value for yOffset"); double yUpperMargin = getDynamic(_Session, "YAXISUPPERMARGIN").getDouble(); if (yUpperMargin < 0) throw newRunTimeException("You must specify a positive value for yAxisUpperMargin"); boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean(); if (bShow3D) throw newRunTimeException("A chart with an xAxisType of 'scale' cannot be displayed in 3D"); boolean bShowMarkers = getDynamic(_Session, "SHOWMARKERS").getBoolean(); boolean bShowBorder = getDynamic(_Session, "SHOWBORDER").getBoolean(); boolean bShowXGridlines = getDynamic(_Session, "SHOWXGRIDLINES").getBoolean(); boolean bShowYGridlines = getDynamic(_Session, "SHOWYGRIDLINES").getBoolean(); boolean bShowLegend = false; // default to false for category charts if (containsAttribute("SHOWLEGEND")) bShowLegend = getDynamic(_Session, "SHOWLEGEND").getBoolean(); int scaleFrom = Integer.MIN_VALUE; if (containsAttribute("SCALEFROM")) scaleFrom = getDynamic(_Session, "SCALEFROM").getInt(); int scaleTo = Integer.MIN_VALUE; if (containsAttribute("SCALETO")) scaleTo = getDynamic(_Session, "SCALETO").getInt(); // Get the plot for the chart and configure it XYPlot plot = getXYPlot(series, xAxisTitle, yAxisTitle, labelFormat, bShowMarkers, markerSize, bShow3D, tipStyle, drillDownUrl, xOffset, yOffset, yAxisUnits, seriesPlacement, height, gridLines); // Render the datasets/series in the order they appear in the cfchart tag plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getDomainAxis().setAxisLinePaint(foregroundColor); plot.getDomainAxis().setLabelPaint(foregroundColor); plot.getDomainAxis().setTickLabelPaint(foregroundColor); plot.getDomainAxis().setUpperMargin(xUpperMargin); plot.setDomainGridlinesVisible(bShowXGridlines); plot.setRangeGridlinesVisible(bShowYGridlines); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); plot.getRangeAxis().setAxisLinePaint(foregroundColor); plot.getRangeAxis().setLabelPaint(foregroundColor); plot.getRangeAxis().setTickLabelPaint(foregroundColor); plot.getRangeAxis().setUpperMargin(yUpperMargin); if (scaleFrom != Integer.MIN_VALUE) plot.getRangeAxis().setLowerBound(scaleFrom); if (scaleTo != Integer.MIN_VALUE) plot.getRangeAxis().setUpperBound(scaleTo); plot.setBackgroundPaint(dataBackgroundColor); plot.setOutlinePaint(foregroundColor); setBackgroundImage(_Session, plot, chartData.getImageData()); // Add Range Markers List<cfCHARTRANGEMARKERData> rangeMarkers = chartData.getRangeMarkers(); for (int i = 0; i < rangeMarkers.size(); i++) addRangeMarker(plot, rangeMarkers.get(i)); // Add Domain Markers List<cfCHARTDOMAINMARKERData> domainMarkers = chartData.getDomainMarkers(); for (int i = 0; i < domainMarkers.size(); i++) addDomainMarker(plot, domainMarkers.get(i)); // Get the chart and configure it JFreeChart chart = new JFreeChart(null, null, plot, false); chart.setBorderVisible(bShowBorder); chart.setBackgroundPaint(backgroundColor); setTitle(chart, title, font, foregroundColor, chartData.getTitles()); setLegend(chart, bShowLegend, font, foregroundColor, backgroundColor, chartData.getLegendData()); return chart; }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private JFreeChart renderPieChart(cfSession _Session, cfCHARTInternalData chartData, List<cfCHARTSERIESData> series, String tipStyle, String drillDownUrl) throws cfmRunTimeException { // Retrieve the attributes of the chart String backgroundColorStr = getDynamic(_Session, "BACKGROUNDCOLOR").toString(); Color backgroundColor = convertStringToColor(backgroundColorStr); String foregroundColorStr = getDynamic(_Session, "FOREGROUNDCOLOR").toString(); Color foregroundColor = convertStringToColor(foregroundColorStr); String labelFormat = getDynamic(_Session, "LABELFORMAT").toString().toLowerCase(); if (!labelFormat.equals("number") && !labelFormat.equals("currency") && !labelFormat.equals("percent")) throw newRunTimeException( "The labelFormat value '" + labelFormat + "' is not supported with pie charts"); String pieSliceStyle = getDynamic(_Session, "PIESLICESTYLE").toString().toLowerCase(); String title = null;/*from ww w . ja v a 2 s .co m*/ if (containsAttribute("TITLE")) title = getDynamic(_Session, "TITLE").toString(); Font font = getFont(_Session); cfCHARTSERIESData seriesData = series.get(0); boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean(); if (bShow3D && !seriesData.getType().equals("pie")) throw newRunTimeException("Only bar, line, horizontal bar and pie charts can be displayed in 3D"); boolean bShowBorder = getDynamic(_Session, "SHOWBORDER").getBoolean(); boolean bShowLegend = true; // default to true for pie charts if (containsAttribute("SHOWLEGEND")) bShowLegend = getDynamic(_Session, "SHOWLEGEND").getBoolean(); // Get the plot for the chart and configure it PiePlot plot = getPiePlot(series, pieSliceStyle, bShow3D); setBackgroundImage(_Session, plot, chartData.getImageData()); plot.setBackgroundPaint(backgroundColor); plot.setLabelBackgroundPaint(backgroundColor); plot.setLabelShadowPaint(backgroundColor); // Set the labels color plot.setLabelPaint(convertStringToColor(seriesData.getDataLabelColor())); // Set the labels font plot.setLabelFont(getFont(seriesData.getDataLabelFont(), seriesData.getDataLabelFontBold(), seriesData.getDataLabelFontItalic(), seriesData.getDataLabelFontSize())); String dataLabelStyle = seriesData.getDataLabelStyle(); NumberFormat percentInstance = NumberFormat.getPercentInstance(); percentInstance.setMaximumFractionDigits(3); NumberFormat numberFormat = null; if (labelFormat.equals("number")) { // Only display the value in the Label as a number numberFormat = NumberFormat.getInstance(); if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}")); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0} {1} ({2} of {3})")); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern)); } } else if (labelFormat.equals("currency")) { // Only display the value in the Label as a currency numberFormat = NumberFormat.getCurrencyInstance(); if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}", NumberFormat.getCurrencyInstance(), percentInstance)); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator( "{0} {1} ({2} of {3})", NumberFormat.getCurrencyInstance(), percentInstance)); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern, NumberFormat.getCurrencyInstance(), percentInstance)); } } else if (labelFormat.equals("percent")) { // Only display the value in the Label as a percent numberFormat = percentInstance; if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}", percentInstance, percentInstance)); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator( "{0} {1} ({2} of {3})", percentInstance, percentInstance)); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern, percentInstance, percentInstance)); } } if (!tipStyle.equals("none")) { plot.setToolTipGenerator(new StandardPieToolTipGenerator( StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT, numberFormat, numberFormat)); } if (drillDownUrl != null) { plot.setURLGenerator(new com.newatlanta.bluedragon.PieURLGenerator(drillDownUrl, numberFormat)); } // Get the chart and configure it JFreeChart chart = new JFreeChart(null, null, plot, false); chart.setBorderVisible(bShowBorder); chart.setBackgroundPaint(backgroundColor); setTitle(chart, title, font, foregroundColor, chartData.getTitles()); setLegend(chart, bShowLegend, font, foregroundColor, backgroundColor, chartData.getLegendData()); return chart; }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private JFreeChart renderCategoryChart(cfSession _Session, cfCHARTInternalData chartData, String tipStyle, String drillDownUrl, String seriesPlacement, int height) throws cfmRunTimeException { List<cfCHARTSERIESData> series = chartData.getSeries(); // Retrieve the attributes of the chart String backgroundColorStr = getDynamic(_Session, "BACKGROUNDCOLOR").toString(); Color backgroundColor = convertStringToColor(backgroundColorStr); String dataBackgroundColorStr = getDynamic(_Session, "DATABACKGROUNDCOLOR").toString(); Color dataBackgroundColor = convertStringToColor(dataBackgroundColorStr); String foregroundColorStr = getDynamic(_Session, "FOREGROUNDCOLOR").toString(); Color foregroundColor = convertStringToColor(foregroundColorStr); String labelFormat = getDynamic(_Session, "LABELFORMAT").toString().toLowerCase(); if (!labelFormat.equals("number") && !labelFormat.equals("currency") && !labelFormat.equals("percent") && !labelFormat.equals("date")) throw newRunTimeException("The labelFormat value '" + labelFormat + "' is not supported"); String xAxisTitle = null;/*from w w w . j a v a2 s .c o m*/ if (containsAttribute("XAXISTITLE")) xAxisTitle = getDynamic(_Session, "XAXISTITLE").toString(); String yAxisTitle = null; if (containsAttribute("YAXISTITLE")) yAxisTitle = getDynamic(_Session, "YAXISTITLE").toString(); String title = null; if (containsAttribute("TITLE")) title = getDynamic(_Session, "TITLE").toString(); Font font = getFont(_Session); int yAxisUnits = 0; if (containsAttribute("YAXISUNITS")) { if (containsAttribute("GRIDLINES")) throw newRunTimeException("You cannot specify both yAxisUnits and gridLines"); yAxisUnits = getDynamic(_Session, "YAXISUNITS").getInt(); if (yAxisUnits < 0) throw newRunTimeException("You must specify a positive value for yAxisUnits"); } int gridLines = -1; if (containsAttribute("GRIDLINES")) { gridLines = getDynamic(_Session, "GRIDLINES").getInt(); if (gridLines < 2) throw newRunTimeException("You must specify a value greater than 1 for gridLines"); } int markerSize = getDynamic(_Session, "MARKERSIZE").getInt(); int xOffset = getDynamic(_Session, "XOFFSET").getInt(); if ((xOffset < 0) || ((xOffset == 0) && (getDynamic(_Session, "XOFFSET").getDouble() != 0))) { // CFMX expects the xOffset value to be between -1 and 1 while BD expects // it to be // between 0 and the chartWidth. This exception should catch people who // are trying // to use this attribute with a CFMX value instead of a BD value. throw newRunTimeException("You must specify an integer value between 0 and the chartWidth for xOffset"); } double xUpperMargin = getDynamic(_Session, "XAXISUPPERMARGIN").getDouble(); if (xUpperMargin < 0) throw newRunTimeException("You must specify a positive value for xAxisUpperMargin"); int yOffset = getDynamic(_Session, "YOFFSET").getInt(); if ((yOffset < 0) || ((yOffset == 0) && (getDynamic(_Session, "YOFFSET").getDouble() != 0))) { // CFMX expects the xOffset value to be between -1 and 1 while BD expects // it to be // between 0 and the chartHeight. This exception should catch people who // are trying // to use this attribute with a CFMX value instead of a BD value. throw newRunTimeException( "You must specify an integer value between 0 and the chartHeight for yOffset"); } double yUpperMargin = getDynamic(_Session, "YAXISUPPERMARGIN").getDouble(); if (yUpperMargin < 0) throw newRunTimeException("You must specify a positive value for yAxisUpperMargin"); boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean(); boolean bShowMarkers = getDynamic(_Session, "SHOWMARKERS").getBoolean(); boolean bShowBorder = getDynamic(_Session, "SHOWBORDER").getBoolean(); boolean bShowXGridlines = getDynamic(_Session, "SHOWXGRIDLINES").getBoolean(); boolean bShowYGridlines = getDynamic(_Session, "SHOWYGRIDLINES").getBoolean(); boolean bSortXAxis = getDynamic(_Session, "SORTXAXIS").getBoolean(); boolean bShowLegend = false; // default to false for category charts if (containsAttribute("SHOWLEGEND")) bShowLegend = getDynamic(_Session, "SHOWLEGEND").getBoolean(); int scaleFrom = Integer.MIN_VALUE; if (containsAttribute("SCALEFROM")) scaleFrom = getDynamic(_Session, "SCALEFROM").getInt(); int scaleTo = Integer.MIN_VALUE; if (containsAttribute("SCALETO")) scaleTo = getDynamic(_Session, "SCALETO").getInt(); String yAxisType = getDynamic(_Session, "YAXISTYPE").toString().toLowerCase(); String[] yAxisSymbols = null; if (yAxisType.equals("symbols")) { if (!containsAttribute("YAXISSYMBOLS")) throw newRunTimeException( "You must specify a value for yAxisSymbols when yAxisType is set to 'symbols'"); String symbols = getDynamic(_Session, "YAXISSYMBOLS").toString(); String symSep = getDynamic(_Session, "SYMBOLSSEPARATOR").toString(); if (symSep.length() != 1) throw newRunTimeException("The symbolsSeparator value must be a single character. The value '" + symSep + "' is not valid."); char symbolsSeparator = symSep.charAt(0); List<String> symbolList = com.nary.util.string.split(symbols, symbolsSeparator); Object[] objs = symbolList.toArray(); yAxisSymbols = new String[objs.length]; for (int x = 0; x < objs.length; x++) yAxisSymbols[x] = (String) objs[x]; } // Get the plot for the chart and configure it CategoryPlot plot = getCategoryPlot(series, xAxisTitle, yAxisTitle, labelFormat, bShowMarkers, markerSize, bShow3D, tipStyle, drillDownUrl, xOffset, yOffset, yAxisUnits, seriesPlacement, bSortXAxis, height, yAxisSymbols, gridLines); // Render the datasets/series in the order they appear in the cfchart tag plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setMaximumCategoryLabelLines(getDynamic(_Session, "MAXCATEGORYLABELLINES").getInt()); String catLblPos = getDynamic(_Session, "CATEGORYLABELPOSITIONS").getString().toLowerCase(); if (catLblPos.equals("vertical")) plot.getDomainAxis().setCategoryLabelPositions(VERTICAL); if (containsAttribute("MAXCATEGORYLABELWIDTHRATIO")) plot.getDomainAxis().setMaximumCategoryLabelWidthRatio( (float) getDynamic(_Session, "MAXCATEGORYLABELWIDTHRATIO").getDouble()); plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getDomainAxis().setAxisLinePaint(foregroundColor); plot.getDomainAxis().setLabelPaint(foregroundColor); plot.getDomainAxis().setTickLabelPaint(foregroundColor); plot.getDomainAxis().setUpperMargin(xUpperMargin); plot.setDomainGridlinesVisible(bShowXGridlines); plot.setRangeGridlinesVisible(bShowYGridlines); plot.getRangeAxis().setLabelFont(font); plot.getRangeAxis().setTickLabelFont(font); plot.getRangeAxis().setAxisLinePaint(foregroundColor); plot.getRangeAxis().setLabelPaint(foregroundColor); plot.getRangeAxis().setTickLabelPaint(foregroundColor); plot.getRangeAxis().setUpperMargin(yUpperMargin); if (scaleFrom != Integer.MIN_VALUE) plot.getRangeAxis().setLowerBound(scaleFrom); if (scaleTo != Integer.MIN_VALUE) plot.getRangeAxis().setUpperBound(scaleTo); plot.setBackgroundPaint(dataBackgroundColor); plot.setOutlinePaint(foregroundColor); setBackgroundImage(_Session, plot, chartData.getImageData()); // Add Range Markers List<cfCHARTRANGEMARKERData> rangeMarkers = chartData.getRangeMarkers(); for (int i = 0; i < rangeMarkers.size(); i++) addRangeMarker(plot, rangeMarkers.get(i)); // Add Domain Markers List<cfCHARTDOMAINMARKERData> domainMarkers = chartData.getDomainMarkers(); for (int i = 0; i < domainMarkers.size(); i++) addDomainMarker(plot, domainMarkers.get(i)); // Get the chart and configure it JFreeChart chart = new JFreeChart(null, null, plot, false); chart.setBorderVisible(bShowBorder); chart.setBackgroundPaint(backgroundColor); setTitle(chart, title, font, foregroundColor, chartData.getTitles()); setLegend(chart, bShowLegend, font, foregroundColor, backgroundColor, chartData.getLegendData()); return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final Plot plot = chart.getPlot(); final PiePlot pp = (PiePlot) plot; final PieDataset pieDS = pp.getDataset(); pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE); if ((explodeSegment != null) && (explodePct != null)) { configureExplode(pp);/* w w w. j a va 2 s .c o m*/ } if (StringUtils.isEmpty(getTooltipFormula()) == false) { pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula())); } if (StringUtils.isEmpty(getUrlFormula()) == false) { pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula())); } pp.setIgnoreNullValues(ignoreNulls); pp.setIgnoreZeroValues(ignoreZeros); if (Boolean.FALSE.equals(getItemsLabelVisible())) { pp.setLabelGenerator(null); } else { final ExpressionRuntime runtime = getRuntime(); final Locale locale = runtime.getResourceBundleFactory().getLocale(); final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale); final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale); final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(), new DecimalFormatSymbols(locale)); numFormat.setRoundingMode(RoundingMode.HALF_UP); final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(), new DecimalFormatSymbols(locale)); percentFormat.setRoundingMode(RoundingMode.HALF_UP); final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat, numFormat, percentFormat); pp.setLabelGenerator(labelGen); final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator( pieLegendLabelFormat, numFormat, percentFormat); pp.setLegendLabelGenerator(legendGen); } if (StringUtils.isEmpty(getLabelFont()) == false) { pp.setLabelFont(Font.decode(getLabelFont())); } if (pieDS != null) { final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { if (i < pieDS.getItemCount()) { pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i])); } else { break; } } } if (shadowPaint != null) { pp.setShadowPaint(shadowPaint); } if (shadowXOffset != null) { pp.setShadowXOffset(shadowXOffset.doubleValue()); } if (shadowYOffset != null) { pp.setShadowYOffset(shadowYOffset.doubleValue()); } pp.setCircular(circular); if (isShowBorder() == false || isChartSectionOutline() == false) { chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void setChartBorder(JFreeChart jfreeChart) { ChartSettings chartSettings = getChartSettings(); JRLineBox lineBox = getChart().getLineBox(); if (lineBox.getLeftPen().getLineWidth().floatValue() == 0 && lineBox.getBottomPen().getLineWidth().floatValue() == 0 && lineBox.getRightPen().getLineWidth().floatValue() == 0 && lineBox.getTopPen().getLineWidth().floatValue() == 0) { boolean isVisible = chartSettings.getBorderVisible() == null ? true : chartSettings.getBorderVisible().booleanValue(); if (isVisible) { Stroke stroke = chartSettings.getBorderStroke(); if (stroke != null) jfreeChart.setBorderStroke(stroke); Paint paint = chartSettings.getBorderPaint() == null ? null : chartSettings.getBorderPaint().getPaint(); if (paint != null) jfreeChart.setBorderPaint(paint); }// w w w .j a v a 2 s .c o m jfreeChart.setBorderVisible(isVisible); } }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected void setChartBorder(JFreeChart jfreeChart) { ChartSettings chartSettings = getChartSettings(); JRLineBox lineBox = getChart().getLineBox(); if (lineBox.getLeftPen().getLineWidth() == 0 && lineBox.getBottomPen().getLineWidth() == 0 && lineBox.getRightPen().getLineWidth() == 0 && lineBox.getTopPen().getLineWidth() == 0) { boolean isVisible = chartSettings.getBorderVisible() == null ? true : chartSettings.getBorderVisible(); if (isVisible) { Stroke stroke = chartSettings.getBorderStroke(); if (stroke != null) jfreeChart.setBorderStroke(stroke); Paint paint = chartSettings.getBorderPaint() == null ? null : chartSettings.getBorderPaint().getPaint(); if (paint != null) jfreeChart.setBorderPaint(paint); }/*from w w w . ja v a 2 s . com*/ jfreeChart.setBorderVisible(isVisible); } }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setChartBorder(JFreeChart jfreeChart) { JRLineBox lineBox = getChart().getLineBox(); if (lineBox.getLeftPen().getLineWidth().floatValue() == 0 && lineBox.getBottomPen().getLineWidth().floatValue() == 0 && lineBox.getRightPen().getLineWidth().floatValue() == 0 && lineBox.getTopPen().getLineWidth().floatValue() == 0) { boolean isVisible = getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_VISIBLE) == null ? false : ((Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_VISIBLE)).booleanValue(); if (isVisible) { BasicStroke stroke = (BasicStroke) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_STROKE); if (stroke != null) jfreeChart.setBorderStroke(stroke); Paint paint = (Paint) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_PAINT); if (paint != null) jfreeChart.setBorderPaint(paint); }//from w w w.j a va2 s . com jfreeChart.setBorderVisible(isVisible); } }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
protected void setChartBorder(JFreeChart jfreeChart) { JRLineBox lineBox = getChart().getLineBox(); if (lineBox.getLeftPen().getLineWidth() == 0 && lineBox.getBottomPen().getLineWidth() == 0 && lineBox.getRightPen().getLineWidth() == 0 && lineBox.getTopPen().getLineWidth() == 0) { boolean isVisible = getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_VISIBLE) == null ? false : (Boolean) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_VISIBLE); if (isVisible) { BasicStroke stroke = (BasicStroke) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_STROKE); if (stroke != null) jfreeChart.setBorderStroke(stroke); Paint paint = (Paint) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.CHART_BORDER_PAINT); if (paint != null) jfreeChart.setBorderPaint(paint); }//w w w .ja va 2s . c o m jfreeChart.setBorderVisible(isVisible); } }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createBarChart(boolean horizontal, boolean stacked, boolean isCombo) throws QueryException { barDataset = new DefaultCategoryDataset(); String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); Object[] charts;/*from w w w . ja va 2s .c o m*/ List<String> legends; Object[] lineCharts = null; String lineLegend = null; if (isCombo) { lineCharts = new Object[1]; if (chart.getYColumnsLegends().size() < chart.getYColumns().size()) { lineLegend = ""; } else { lineLegend = chart.getYColumnsLegends().get(chart.getYColumns().size() - 1); } charts = new Object[chart.getYColumns().size() - 1]; legends = chart.getYColumnsLegends().subList(0, chart.getYColumns().size() - 1); } else { charts = new Object[chart.getYColumns().size()]; legends = chart.getYColumnsLegends(); } boolean hasLegend = false; for (int i = 0; i < charts.length; i++) { String legend = ""; try { legend = replaceParameters(legends.get(i)); legend = StringUtil.getI18nString(legend, I18nUtil.getLanguageByName(chart, language)); } catch (IndexOutOfBoundsException ex) { // no legend set } // Important : must have default different legends used in barDataset.addValue if ((legend == null) || "".equals(legend.trim())) { legend = DEFAULT_LEGEND_PREFIX + String.valueOf(i + 1); } else { hasLegend = true; } charts[i] = legend; } if (isCombo) { String leg = ""; if (lineLegend != null) { leg = replaceParameters(lineLegend); } lineCharts[0] = leg; } byte style = chart.getType().getStyle(); JFreeChart jfreechart; String xLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); String yLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); PlotOrientation plotOrientation = horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL; if (stacked) { jfreechart = ChartFactory.createStackedBarChart(chartTitle, // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data plotOrientation, // orientation true, // include legend true, // tooltips false // URLs ); } else { switch (style) { case ChartType.STYLE_BAR_PARALLELIPIPED: case ChartType.STYLE_BAR_CYLINDER: jfreechart = ChartFactory.createBarChart3D(chartTitle, // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data plotOrientation, // orientation true, // include legend true, // tooltips false // URLs ); break; default: jfreechart = ChartFactory.createBarChart(chartTitle, // chart title xLegend, // x-axis Label yLegend, // y-axis Label barDataset, // data plotOrientation, // orientation true, // include legend true, // tooltips false // URLs ); break; } } if (style == ChartType.STYLE_BAR_CYLINDER) { ((CategoryPlot) jfreechart.getPlot()).setRenderer(new CylinderRenderer()); } // hide legend if necessary if (!hasLegend) { jfreechart.removeLegend(); } // hide border jfreechart.setBorderVisible(false); // title setTitle(jfreechart); // chart colors & values shown on bars boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); CategoryPlot plot = (CategoryPlot) jfreechart.getPlot(); plot.setForegroundAlpha(transparency); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } for (int i = 0; i < charts.length; i++) { renderer.setSeriesPaint(i, chart.getForegrounds().get(i)); if (showValues) { renderer.setSeriesItemLabelsVisible(i, true); renderer.setSeriesItemLabelGenerator(i, new StandardCategoryItemLabelGenerator("{2}", decimalformat, percentageFormat)); } } if (showValues) { // increase a little bit the range axis to view all item label values over bars plot.getRangeAxis().setUpperMargin(0.2); } // grid axis visibility & colors if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) { plot.setDomainGridlinesVisible(false); } else { if (chart.getXGridColor() != null) { plot.setDomainGridlinePaint(chart.getXGridColor()); } else { plot.setDomainGridlinePaint(Color.BLACK); } } if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) { plot.setRangeGridlinesVisible(false); } else { if (chart.getYGridColor() != null) { plot.setRangeGridlinePaint(chart.getYGridColor()); } else { plot.setRangeGridlinePaint(Color.BLACK); } } // chart background plot.setBackgroundPaint(chart.getBackground()); // labels color plot.getDomainAxis().setTickLabelPaint(chart.getXColor()); plot.getRangeAxis().setTickLabelPaint(chart.getYColor()); // legend color plot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor()); plot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor()); // legend font plot.getDomainAxis().setLabelFont(chart.getXLegend().getFont()); plot.getRangeAxis().setLabelFont(chart.getYLegend().getFont()); // axis color plot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor()); plot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor()); // hide labels if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) { plot.getDomainAxis().setTickLabelsVisible(false); plot.getDomainAxis().setTickMarksVisible(false); } if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) { plot.getRangeAxis().setTickLabelsVisible(false); plot.getRangeAxis().setTickMarksVisible(false); } if (chart.getType().getStyle() == ChartType.STYLE_NORMAL) { // no shadow renderer.setShadowVisible(false); // no gradient renderer.setBarPainter(new StandardBarPainter()); } // label orientation CategoryAxis domainAxis = plot.getDomainAxis(); if (chart.getXorientation() == Chart.VERTICAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2)); } else if (chart.getXorientation() == Chart.DIAGONAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4)); } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) { domainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8)); } // labels fonts domainAxis.setTickLabelFont(chart.getXLabelFont()); plot.getRangeAxis().setTickLabelFont(chart.getYLabelFont()); createChart(plot.getRangeAxis(), charts); if (isCombo) { addLineChartOverBar(jfreechart, lineCharts, lineLegend); } return jfreechart; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
protected void initChart(JFreeChart chart, ChartModel chartModel) { if (chartModel.getBackground() instanceof Integer) { chart.setBackgroundPaint(new Color(0x00FFFFFF & (Integer) chartModel.getBackground())); } else {/* w w w.java2s .c om*/ chart.setBackgroundPaint(Color.WHITE); } if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null) && (chartModel.getTitle().getText().trim().length() > 0)) { Font font = ChartUtils.getFont(chartModel.getTitle().getFontFamily(), chartModel.getTitle().getFontStyle(), chartModel.getTitle().getFontWeight(), chartModel.getTitle().getFontSize()); if (font != null) { chart.getTitle().setFont(font); } RectangleEdge rectangleEdge = RectangleEdge.TOP; if (chartModel.getTitle().getLocation() != null) { switch (chartModel.getTitle().getLocation()) { case RIGHT: rectangleEdge = RectangleEdge.BOTTOM; break; case LEFT: rectangleEdge = RectangleEdge.LEFT; break; case BOTTOM: rectangleEdge = RectangleEdge.BOTTOM; break; } } chart.getTitle().setPosition(rectangleEdge); if (RectangleEdge.isTopOrBottom(rectangleEdge)) { HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER; if (chartModel.getTitle().getAlignment() != null) { switch (chartModel.getTitle().getAlignment()) { case LEFT: horizontalAlignment = horizontalAlignment.LEFT; break; case RIGHT: horizontalAlignment = horizontalAlignment.RIGHT; break; } } chart.getTitle().setHorizontalAlignment(horizontalAlignment); } } if ((chartModel.getLegend() != null) && chartModel.getLegend().getVisible()) { Font font = ChartUtils.getFont(chartModel.getLegend().getFontFamily(), chartModel.getLegend().getFontStyle(), chartModel.getLegend().getFontWeight(), chartModel.getLegend().getFontSize()); if (font != null) { chart.getLegend().setItemFont(font); } if (!chartModel.getLegend().getBorderVisible()) { chart.getLegend().setFrame(BlockBorder.NONE); } } chart.setBorderVisible(chartModel.getBorderVisible()); if (chartModel.getBorderColor() instanceof Integer) { chart.setBorderPaint(new Color(0x00FFFFFF & (Integer) chartModel.getBorderColor())); } for (StyledText subtitle : chartModel.getSubtitles()) { if ((subtitle.getText()) != null && (subtitle.getText().trim().length() > 0)) { TextTitle textTitle = new TextTitle(subtitle.getText()); Font font = ChartUtils.getFont(subtitle.getFontFamily(), subtitle.getFontStyle(), subtitle.getFontWeight(), subtitle.getFontSize()); if (font != null) { textTitle.setFont(font); } if (subtitle.getColor() != null) { textTitle.setPaint(new Color(0x00FFFFFF & subtitle.getColor())); } if (subtitle.getBackgroundColor() != null) { textTitle.setBackgroundPaint(new Color(0x00FFFFFF & subtitle.getBackgroundColor())); } chart.addSubtitle(textTitle); } } }