List of usage examples for org.jfree.chart StandardChartTheme createLegacyTheme
public static ChartTheme createLegacyTheme()
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC Zqin Comment method "createBoxAndWhiskerChart". * /* ww w. j a v a 2 s .c om*/ * @param title * @param dataset * @return */ public static JFreeChart createBoxAndWhiskerChart(String title, BoxAndWhiskerCategoryDataset dataset) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, title, Messages.getString("TopChartFactory.Value"), dataset, false); //$NON-NLS-1$ CategoryPlot plot = chart.getCategoryPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(false); double min = dataset.getMinRegularValue("0", "").doubleValue(); //$NON-NLS-1$ //$NON-NLS-2$ double max = dataset.getMaxRegularValue("0", "").doubleValue(); //$NON-NLS-1$ //$NON-NLS-2$ double unit = (max - min) / 10; rangeAxis.setRange(min - unit, max + unit); rangeAxis.setTickUnit(new NumberTickUnit(unit)); BoxAndWhiskerRenderer renderer = (BoxAndWhiskerRenderer) plot.getRenderer(); renderer.setArtifactPaint(ChartDecorator.COLOR_LIST.get(1)); return chart; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * *//*from w w w. java2s. co m*/ protected JFreeChart createBarChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createBarChart( (String) evaluateExpression(getChart().getTitleExpression()), (String) evaluateExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()), (String) evaluateExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); JRBarPlot barPlot = (JRBarPlot) getPlot(); boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks().booleanValue(); boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels().booleanValue(); categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks); categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), false, (Comparable) evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(barPlot.getDomainAxisMaxValueExpression())); ((NumberAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks); ((NumberAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the value axis configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), true, (Comparable) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(barPlot.getRangeAxisMaxValueExpression())); BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels().booleanValue(); categoryRenderer.setBaseItemLabelsVisible(isShowLabels); if (isShowLabels) { JRItemLabel itemLabel = barPlot.getItemLabel(); Integer baseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null; categoryRenderer.setBaseItemLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize)); if (itemLabel != null) { if (itemLabel.getColor() != null) { categoryRenderer.setBaseItemLabelPaint(itemLabel.getColor()); } else { categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } // categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor()); // if(itemLabel.getMask() != null) // { // categoryRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( // StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, // new DecimalFormat(itemLabel.getMask()))); // } // else // { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); // } } else { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } } categoryRenderer.setShadowVisible(false); return jfreeChart; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *//* ww w . j a v a2 s . co m*/ protected JFreeChart createAreaChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createAreaChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRAreaPlot) getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRAreaPlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart); JRAreaPlot areaPlot = (JRAreaPlot) getPlot(); // Handle the axis formating for the category axis configureAxis(((CategoryPlot) jfreeChart.getPlot()).getDomainAxis(), areaPlot.getCategoryAxisLabelFont(), areaPlot.getCategoryAxisLabelColor(), areaPlot.getCategoryAxisTickLabelFont(), areaPlot.getCategoryAxisTickLabelColor(), areaPlot.getCategoryAxisTickLabelMask(), areaPlot.getCategoryAxisVerticalTickLabels(), areaPlot.getCategoryAxisLineColor(), false, (Comparable<?>) evaluateExpression(areaPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(areaPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(((CategoryPlot) jfreeChart.getPlot()).getRangeAxis(), areaPlot.getValueAxisLabelFont(), areaPlot.getValueAxisLabelColor(), areaPlot.getValueAxisTickLabelFont(), areaPlot.getValueAxisTickLabelColor(), areaPlot.getValueAxisTickLabelMask(), areaPlot.getValueAxisVerticalTickLabels(), areaPlot.getValueAxisLineColor(), true, (Comparable<?>) evaluateExpression(areaPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(areaPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * *//*w w w . ja v a2s . c o m*/ protected JFreeChart createBarChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createBarChart(evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); JRBarPlot barPlot = (JRBarPlot) getPlot(); boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks(); boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels(); categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks); categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), false, (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMaxValueExpression())); ((NumberAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks); ((NumberAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the value axis Comparable<?> rangeAxisMaxValue = (Comparable<?>) evaluateExpression( barPlot.getRangeAxisMaxValueExpression()); configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), true, (Comparable<?>) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), rangeAxisMaxValue); BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels(); categoryRenderer.setBaseItemLabelsVisible(isShowLabels); if (isShowLabels) { if (rangeAxisMaxValue == null) { //in case the bars are horizontal and there was no range max value specified, //we try to make the axis a little longer for labels to fit on the plot Axis axis = categoryPlot.getRangeAxis(); if (axis instanceof ValueAxis) { if (!(axis instanceof DateAxis)) { float rangeAxisMaxRatio = 1f; if (barPlot.getOrientationValue() == PlotOrientationEnum.HORIZONTAL) { rangeAxisMaxRatio = JRPropertiesUtil .getInstance(getChartContext().getJasperReportsContext()) .getFloatProperty(getChart(), "net.sf.jasperreports.chart.bar.horizontal.range.max.value.ratio", 1.25f); } else { rangeAxisMaxRatio = JRPropertiesUtil .getInstance(getChartContext().getJasperReportsContext()) .getFloatProperty(getChart(), "net.sf.jasperreports.chart.bar.vertical.range.max.value.ratio", 1.1f); } ((ValueAxis) axis).setUpperBound(((ValueAxis) axis).getUpperBound() * rangeAxisMaxRatio); } } } JRItemLabel itemLabel = barPlot.getItemLabel(); Integer baseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : null; categoryRenderer.setBaseItemLabelFont(getFont(new JRBaseFont(getChart(), null), font, baseFontSize)); if (itemLabel != null) { if (itemLabel.getColor() != null) { categoryRenderer.setBaseItemLabelPaint(itemLabel.getColor()); } else { categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } // categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor()); // if (itemLabel.getMask() != null) // { // categoryRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( // StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, // new DecimalFormat(itemLabel.getMask()))); // } // else // { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); // } } else { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } } categoryRenderer.setShadowVisible(false); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * *///from w w w . j a v a 2 s . co m protected JFreeChart createBarChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createBarChart( (String) evaluateExpression(getChart().getTitleExpression()), (String) evaluateExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()), (String) evaluateExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); JRBarPlot barPlot = (JRBarPlot) getPlot(); boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks().booleanValue(); boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels().booleanValue(); categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks); categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), (Comparable) evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(barPlot.getDomainAxisMaxValueExpression())); ((NumberAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks); ((NumberAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the value axis configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), (Comparable) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(barPlot.getRangeAxisMaxValueExpression())); BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels().booleanValue(); categoryRenderer.setBaseItemLabelsVisible(isShowLabels); if (isShowLabels) { JRItemLabel itemLabel = barPlot.getItemLabel(); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : new JRBaseFont(getChart(), null); categoryRenderer.setBaseItemLabelFont(JRFontUtil.getAwtFont(font, getLocale())); if (itemLabel != null) { if (itemLabel.getColor() != null) { categoryRenderer.setBaseItemLabelPaint(itemLabel.getColor()); } else { categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } // categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor()); // if(itemLabel.getMask() != null) // { // categoryRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( // StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, // new DecimalFormat(itemLabel.getMask()))); // } // else // { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); // } } else { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } } categoryRenderer.setShadowVisible(false); return jfreeChart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC xqliu Comment method "createStackedBarChart". * //from w w w .jav a 2 s . com * @param title * @param domainAxisLabel * @param rangeAxisLabel * @param dataset * @param orientation * @param legend * @param tooltips * @param urls * @return */ public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ final JFreeChart chart = ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeGridlinesVisible(true); StackedBarRenderer sbr = (StackedBarRenderer) plot.getRenderer(); sbr.setBaseItemLabelsVisible(true); sbr.setRenderAsPercentages(true); sbr.setBaseItemLabelGenerator(new DQRuleItemLabelGenerator("{3}", NumberFormat.getIntegerInstance())); //$NON-NLS-1$ sbr.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); // ADD xqliu 2010-03-10 feature 10834 // sbr.setBaseToolTipGenerator(new DQRuleToolTipGenerator(ChartDecorator.NEW_TOOL_TIP_FORMAT_STRING, // NumberFormat // .getInstance())); // ~10834 // ADD TDQ-5251 msjian 2012-7-31: do not display the shadow sbr.setShadowVisible(false); // TDQ-5251~ NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis.setUpperMargin(0.05f); axis.setLowerMargin(0.01f); return chart; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
protected JFreeChart createBar3DChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createBarChart3D( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRBar3DPlot) getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRBar3DPlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false);/* ww w .jav a 2s . c om*/ configureChart(jfreeChart); CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot(); JRBar3DPlot bar3DPlot = (JRBar3DPlot) getPlot(); BarRenderer3D barRenderer3D = new BarRenderer3D( bar3DPlot.getXOffsetDouble() == null ? BarRenderer3D.DEFAULT_X_OFFSET : bar3DPlot.getXOffsetDouble(), bar3DPlot.getYOffsetDouble() == null ? BarRenderer3D.DEFAULT_Y_OFFSET : bar3DPlot.getYOffsetDouble()); boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels(); barRenderer3D.setBaseItemLabelsVisible(isShowLabels); if (isShowLabels) { JRItemLabel itemLabel = bar3DPlot.getItemLabel(); barRenderer3D.setBaseItemLabelFont( fontUtil.getAwtFont(getFont(itemLabel == null ? null : itemLabel.getFont()), getLocale())); if (itemLabel != null) { if (itemLabel.getColor() != null) { barRenderer3D.setBaseItemLabelPaint(itemLabel.getColor()); } else { barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor()); } // categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor()); // if (itemLabel.getMask() != null) // { // barRenderer3D.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( // StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, // new DecimalFormat(itemLabel.getMask()))); // } // else // { barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); // } } else { barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor()); } } categoryPlot.setRenderer(barRenderer3D); // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(), bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(), bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(), bar3DPlot.getCategoryAxisVerticalTickLabels(), bar3DPlot.getCategoryAxisLineColor(), false, (Comparable<?>) evaluateExpression(bar3DPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(bar3DPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(), bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(), bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(), bar3DPlot.getValueAxisVerticalTickLabels(), bar3DPlot.getValueAxisLineColor(), true, (Comparable<?>) evaluateExpression(bar3DPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(bar3DPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * *///from www . j a v a 2 s . com protected JFreeChart createBarChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createBarChart(evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()), (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot(); //plot.setNoDataMessage("No data to display"); JRBarPlot barPlot = (JRBarPlot) getPlot(); boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks(); boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels(); categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks); categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the category axis configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(), barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(), barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(), barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMaxValueExpression())); ((NumberAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks); ((NumberAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels); // Handle the axis formating for the value axis Comparable<?> rangeAxisMaxValue = (Comparable<?>) evaluateExpression( barPlot.getRangeAxisMaxValueExpression()); configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(), barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(), barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(), barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), (Comparable<?>) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), rangeAxisMaxValue); BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer(); boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels(); categoryRenderer.setBaseItemLabelsVisible(isShowLabels); if (isShowLabels) { if (rangeAxisMaxValue == null) { //in case the bars are horizontal and there was no range max value specified, //we try to make the axis a little longer for labels to fit on the plot Axis axis = categoryPlot.getRangeAxis(); if (axis instanceof ValueAxis) { if (!(axis instanceof DateAxis)) { float rangeAxisMaxRatio = 1f; if (barPlot.getOrientationValue() == PlotOrientationEnum.HORIZONTAL) { rangeAxisMaxRatio = JRPropertiesUtil .getInstance(getChartContext().getJasperReportsContext()) .getFloatProperty(getChart(), "net.sf.jasperreports.chart.bar.horizontal.range.max.value.ratio", 1.25f); } else { rangeAxisMaxRatio = JRPropertiesUtil .getInstance(getChartContext().getJasperReportsContext()) .getFloatProperty(getChart(), "net.sf.jasperreports.chart.bar.vertical.range.max.value.ratio", 1.1f); } ((ValueAxis) axis).setUpperBound(((ValueAxis) axis).getUpperBound() * rangeAxisMaxRatio); } } } JRItemLabel itemLabel = barPlot.getItemLabel(); JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont() : new JRBaseFont(getChart(), null); categoryRenderer.setBaseItemLabelFont(getFontUtil().getAwtFont(font, getLocale())); if (itemLabel != null) { if (itemLabel.getColor() != null) { categoryRenderer.setBaseItemLabelPaint(itemLabel.getColor()); } else { categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } // categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor()); // if (itemLabel.getMask() != null) // { // categoryRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( // StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, // new DecimalFormat(itemLabel.getMask()))); // } // else // { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); // } } else { categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator()); categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor()); } } categoryRenderer.setShadowVisible(false); return jfreeChart; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * DOC xqliu Comment method "createLineChart". * // w w w.j av a2 s . co m * @param title * @param dataset * @param showLegend * @return */ public static JFreeChart createLineChart(String title, XYDataset dataset, boolean showLegend) { // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); // TDQ-5112~ final JFreeChart chart = ChartFactory.createXYLineChart(null, title, Messages.getString("TopChartFactory.Percent"), dataset, PlotOrientation.VERTICAL, //$NON-NLS-1$ showLegend, false, false); final XYPlot plot = chart.getXYPlot(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected JFreeChart createBubbleChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createBubbleChart( (String) evaluateExpression(getChart().getTitleExpression()), (String) evaluateExpression(((JRBubblePlot) getPlot()).getXAxisLabelExpression()), (String) evaluateExpression(((JRBubblePlot) getPlot()).getYAxisLabelExpression()), (XYZDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRBubblePlot bubblePlot = (JRBubblePlot) getPlot(); int scaleType = bubblePlot.getScaleTypeValue() == null ? ScaleTypeEnum.ON_RANGE_AXIS.getValue() : bubblePlot.getScaleTypeValue().getValue(); XYBubbleRenderer bubbleRenderer = new XYBubbleRenderer(scaleType); xyPlot.setRenderer(bubbleRenderer);/*from w w w . j a va 2 s . co m*/ // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), bubblePlot.getXAxisLabelFont(), bubblePlot.getXAxisLabelColor(), bubblePlot.getXAxisTickLabelFont(), bubblePlot.getXAxisTickLabelColor(), bubblePlot.getXAxisTickLabelMask(), bubblePlot.getXAxisVerticalTickLabels(), bubblePlot.getOwnXAxisLineColor(), false, (Comparable) evaluateExpression(bubblePlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(bubblePlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), bubblePlot.getYAxisLabelFont(), bubblePlot.getYAxisLabelColor(), bubblePlot.getYAxisTickLabelFont(), bubblePlot.getYAxisTickLabelColor(), bubblePlot.getYAxisTickLabelMask(), bubblePlot.getYAxisVerticalTickLabels(), bubblePlot.getOwnYAxisLineColor(), true, (Comparable) evaluateExpression(bubblePlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(bubblePlot.getRangeAxisMaxValueExpression())); return jfreeChart; }