List of usage examples for org.jfree.chart JFreeChart setAntiAlias
public void setAntiAlias(boolean flag)
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createToolAnalysisChart(int width, int height) { CategoryDataset dataset = getToolAnalysisDataSet(); if (dataset == null) { return generateNoDataChart(width, height); }//from w ww.j a v a 2s .co m JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // the plot orientation false, // legend false, // tooltips false // urls ); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set transparency plot.setForegroundAlpha(0.7f); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin(0); domainAxis.setLowerMargin(0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.20); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{1}", NumberFormat.getInstance(new ResourceLoader().getLocale())); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 9)); renderer.setBaseItemLabelsVisible(true); renderer.setItemMargin(0); renderer.setSeriesPaint(0, Color.BLUE); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generateLineChart(String siteId, CategoryDataset dataset, int width, int height, boolean render3d, float transparency, boolean itemLabelsVisible, boolean smallFontInDomainAxis) { JFreeChart chart = null; if (render3d) chart = ChartFactory.createLineChart3D(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);//w ww .j a v a 2 s. co m else chart = ChartFactory.createLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set antialias chart.setAntiAlias(true); // set domain axis font size if (smallFontInDomainAxis && !canUseNormalFontSize(width)) { plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 8)); plot.getDomainAxis().setCategoryMargin(0.05); } // set outline LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setDrawOutlines(true); // item labels if (itemLabelsVisible) { plot.getRangeAxis().setUpperMargin(0.2); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(CategoryDataset dataset, int row, int column) { Number n = dataset.getValue(row, column); if (n.intValue() != 0) //return n.intValue()+""; return n.toString(); return ""; } }); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 8)); renderer.setItemLabelsVisible(true); } BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
@Override public iPlatformComponent createChart(iPlatformComponent chartComponent, final ChartDefinition cd) { ChartInfo ci = (ChartInfo) cd.getChartHandlerInfo(); if (ci != null) { ci.dispose();//from w w w. j av a 2 s . com } ci = new ChartInfo(); cd.setChartHandlerInfo(ci); ChartPanelEx chartPanel = (ChartPanelEx) ((chartComponent == null) ? null : chartComponent.getView()); if (chartPanel == null) { chartPanel = createChartPanel(null, cd); chartComponent = new Container(chartPanel); if (chartForeground != null) { chartComponent.setForeground(chartForeground); } if (chartFont != null) { chartComponent.setFont(chartFont); } if (chartBackground != null) { chartComponent.setBackground(chartBackground); } } ci.popularSeriesDataAndCaluclateRanges(this, cd); JFreeChart chart = createCharts(chartPanel, cd); chartPanel.setChart(chart); chart.setAntiAlias(true); chart.setBackgroundPaint(null); chart.setBorderVisible(false); if (!cd.isAllowZooming()) { chartPanel.setRangeZoomable(false); chartPanel.setDomainZoomable(false); } ci.chart = chart; ChartHelper.setChartTitle(chart, cd.getTitle()); if (cd.isShowLegends()) { LegendTitle l = new LegendTitle(chart.getPlot()); l.setItemPaint(cd.getTextColor(legendLabelColor)); l.setItemFont(cd.getTextFont(legendLabelFont)); switch (cd.getLegendSide()) { case TOP: l.setPosition(RectangleEdge.TOP); break; case BOTTOM: l.setPosition(RectangleEdge.BOTTOM); break; case LEFT: l.setPosition(RectangleEdge.LEFT); break; default: l.setPosition(RectangleEdge.RIGHT); break; } chart.addSubtitle(l); } ChartFactory.getChartTheme().apply(chart); ((ChartInfo) cd.getChartHandlerInfo()).chartPanel = chartPanel; if ((cd.getSeriesCount() > 0) && (chartPanel.getHeight() > 0)) { chartPanel.updateTickmarks(chartPanel.getWidth(), chartPanel.getHeight()); } return chartComponent; }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generateTimeSeriesChart(String siteId, IntervalXYDataset dataset, int width, int height, boolean renderBar, float transparency, boolean itemLabelsVisible, boolean smallFontInDomainAxis, String timePeriod, Date firstDate, Date lastDate) { JFreeChart chart = null; if (!renderBar) { chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, true, false, false); } else {//from ww w . java 2s . c o m chart = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL, true, false, false); } XYPlot plot = (XYPlot) chart.getPlot(); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set antialias chart.setAntiAlias(true); // set domain axis font size if (smallFontInDomainAxis && !canUseNormalFontSize(width)) { plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 8)); } // configure date display (localized) in domain axis Locale locale = msgs.getLocale(); PeriodAxis periodaxis = new PeriodAxis(null); Class timePeriodClass = null; if (dataset instanceof TimeSeriesCollection) { TimeSeriesCollection tsc = (TimeSeriesCollection) dataset; if (tsc.getSeriesCount() > 0) { timePeriodClass = tsc.getSeries(0).getTimePeriodClass(); } else { timePeriodClass = org.jfree.data.time.Day.class; } periodaxis.setAutoRangeTimePeriodClass(timePeriodClass); } PeriodAxisLabelInfo aperiodaxislabelinfo[] = null; if (StatsManager.CHARTTIMESERIES_WEEKDAY.equals(timePeriod)) { aperiodaxislabelinfo = new PeriodAxisLabelInfo[2]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("E", locale)); aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d", locale)); } else if (StatsManager.CHARTTIMESERIES_DAY.equals(timePeriod)) { aperiodaxislabelinfo = new PeriodAxisLabelInfo[3]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d", locale)); aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM", locale)); aperiodaxislabelinfo[2] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class, new SimpleDateFormat("yyyy", locale)); } else if (StatsManager.CHARTTIMESERIES_MONTH.equals(timePeriod)) { aperiodaxislabelinfo = new PeriodAxisLabelInfo[2]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM", locale)); aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class, new SimpleDateFormat("yyyy", locale)); } else if (StatsManager.CHARTTIMESERIES_YEAR.equals(timePeriod)) { aperiodaxislabelinfo = new PeriodAxisLabelInfo[1]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class, new SimpleDateFormat("yyyy", locale)); } periodaxis.setLabelInfo(aperiodaxislabelinfo); // date range if (firstDate != null || lastDate != null) { periodaxis.setAutoRange(false); if (firstDate != null) { if (StatsManager.CHARTTIMESERIES_MONTH.equals(timePeriod) || StatsManager.CHARTTIMESERIES_YEAR.equals(timePeriod)) { periodaxis.setFirst(new org.jfree.data.time.Month(firstDate)); } else { periodaxis.setFirst(new org.jfree.data.time.Day(firstDate)); } } if (lastDate != null) { if (StatsManager.CHARTTIMESERIES_MONTH.equals(timePeriod) || StatsManager.CHARTTIMESERIES_YEAR.equals(timePeriod)) { periodaxis.setLast(new org.jfree.data.time.Month(lastDate)); } else { periodaxis.setLast(new org.jfree.data.time.Day(lastDate)); } } } periodaxis.setTickMarkOutsideLength(0.0F); plot.setDomainAxis(periodaxis); // set outline AbstractXYItemRenderer renderer = (AbstractXYItemRenderer) plot.getRenderer(); if (renderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) renderer; r.setDrawSeriesLineAsPath(true); r.setShapesVisible(true); r.setShapesFilled(true); } else if (renderer instanceof XYBarRenderer) { //XYBarRenderer r = (XYBarRenderer) renderer; ClusteredXYBarRenderer r = new ClusteredXYBarRenderer(); r.setDrawBarOutline(true); if (smallFontInDomainAxis && !canUseNormalFontSize(width)) r.setMargin(0.05); else r.setMargin(0.10); plot.setRenderer(r); renderer = r; } // item labels if (itemLabelsVisible) { plot.getRangeAxis().setUpperMargin(0.2); renderer.setItemLabelGenerator(new XYItemLabelGenerator() { private static final long serialVersionUID = 1L; public String generateLabel(XYDataset dataset, int series, int item) { Number n = dataset.getY(series, item); if (n.doubleValue() != 0) return n.toString(); return ""; } }); renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 8)); renderer.setItemLabelsVisible(true); } BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generatePieChart(String siteId, PieDataset dataset, int width, int height, boolean render3d, float transparency, boolean smallFontInDomainAxis) { JFreeChart chart = null; if (render3d) chart = ChartFactory.createPieChart3D(null, dataset, false, false, false); else//from ww w. j a v a2s. co m chart = ChartFactory.createPieChart(null, dataset, false, false, false); PiePlot plot = (PiePlot) chart.getPlot(); // set start angle (135 or 150 deg so minor data has more space on the left) plot.setStartAngle(150D); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // fix border offset chart.setPadding(new RectangleInsets(5, 5, 5, 5)); plot.setInsets(new RectangleInsets(1, 1, 1, 1)); // set chart border plot.setOutlinePaint(null); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set antialias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generateBarChart(String siteId, CategoryDataset dataset, int width, int height, boolean render3d, float transparency, boolean itemLabelsVisible, boolean smallFontInDomainAxis) { JFreeChart chart = null; if (render3d) chart = ChartFactory.createBarChart3D(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false);//from w w w.j av a 2 s . co m else chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // allow longer legends (prevent truncation) plot.getDomainAxis().setMaximumCategoryLabelLines(50); plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(1.0f); // set antialias chart.setAntiAlias(true); // set domain axis font size if (smallFontInDomainAxis && !canUseNormalFontSize(width)) { plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 8)); plot.getDomainAxis().setCategoryMargin(0.05); } // set bar outline BarRenderer barrenderer = (BarRenderer) plot.getRenderer(); barrenderer.setDrawBarOutline(true); if (smallFontInDomainAxis && !canUseNormalFontSize(width)) barrenderer.setItemMargin(0.05); else barrenderer.setItemMargin(0.10); // item labels if (itemLabelsVisible) { plot.getRangeAxis().setUpperMargin(0.2); barrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(CategoryDataset dataset, int row, int column) { Number n = dataset.getValue(row, column); if (n.doubleValue() != 0) { if ((double) n.intValue() == n.doubleValue()) return Integer.toString(n.intValue()); else return Double.toString(Util.round(n.doubleValue(), 1)); } return ""; } }); barrenderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 8)); barrenderer.setItemLabelsVisible(true); } BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java
private static void applyProperties(JFreeChart chart, Map<String, Object> properties) { if (properties != null) { String text = (String) properties.get(TITLE); if (text != null) { TextTitle title = chart.getTitle(); if (title == null) { title = new TextTitle(); chart.setTitle(title);//w w w. j a v a 2 s .c o m } title.setText(text); Font titleFont = (Font) properties.get(TITLEFONT); if (titleFont != null) title.setFont(titleFont); Paint paint = (Paint) properties.get(TITLECOLOR); if (paint != null) title.setPaint(paint); } else chart.setTitle((TextTitle) null); Plot plot = chart.getPlot(); Paint paint = (Paint) properties.get(BGCOLOR); if (paint != null) plot.setBackgroundPaint(paint); paint = (Color) properties.get(OUTLINEPAINT); if (paint != null) plot.setOutlinePaint(paint); Stroke stroke = (Stroke) properties.get(OUTLINESTROKE); if (stroke != null) plot.setOutlineStroke(stroke); PlotOrientation orientation = (PlotOrientation) properties.get(ORIENTATION); Axis domainAxis = null; Axis rangeAxis = null; if (plot instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); if (orientation != null) p.setOrientation(orientation); } else if (plot instanceof XYPlot) { XYPlot p = (XYPlot) plot; domainAxis = p.getDomainAxis(); rangeAxis = p.getRangeAxis(); if (orientation != null) p.setOrientation(orientation); } if (domainAxis != null) applyAxisProperties(domainAxis, "x", properties); //$NON-NLS-1$ if (rangeAxis != null) applyAxisProperties(rangeAxis, "y", properties); //$NON-NLS-1$ Boolean anti = (Boolean) properties.get(ANTIALIAS); if (anti != null) chart.setAntiAlias(anti); paint = (Paint) properties.get(CANVASPAINT); if (paint != null) chart.setBackgroundPaint(paint); } }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * */// ww w.j a va 2s . c o m protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException { ChartSettings chartSettings = getChartSettings(); setChartBackground(jfreeChart); setChartTitle(jfreeChart); setChartSubtitles(jfreeChart); setChartLegend(jfreeChart); setChartBorder(jfreeChart); Boolean chartAntiAlias = chartSettings.getAntiAlias(); if (chartAntiAlias != null) jfreeChart.setAntiAlias(chartAntiAlias.booleanValue()); Boolean textAntiAlias = chartSettings.getTextAntiAlias(); if (textAntiAlias != null) jfreeChart.setTextAntiAlias(textAntiAlias.booleanValue()); RectangleInsets padding = chartSettings.getPadding(); if (padding != null) { jfreeChart.setPadding(padding);//FIXMETHEME consider using linebox } configurePlot(jfreeChart.getPlot(), jrPlot); }
From source file:ru.spbspu.viewer.DataView.java
/** * ? //from w w w.j a v a2 s . co m */ public void buildFourierTransformGraph() { CategoryTableXYDataset serie = new CategoryTableXYDataset(); serie.setNotify(false); double[] data = _presenter.getFourierTransform(getFramePosition(), getFrameWidth(), getWindowWidth()); JFreeChart chart = null; String select = v.getSelection().getActionCommand(); if (select.equalsIgnoreCase(vAcceleration.getActionCommand())) { for (int i = 0; i < data.length; i++) { serie.add(1.0 * i / getFrameWidth() * getDiscretization(), 2.0 * data[i], ""); } chart = ChartFactory.createXYLineChart("", "", "g, /?^2", serie); } else if (select.equalsIgnoreCase(vDisplacement.getActionCommand())) { for (int i = 0; i < data.length; i++) { double freq = 1.0 * i / getFrameWidth() * getDiscretization(); if (freq < 1.0) { continue; } double value = 2.0 * data[i] * Math.pow(10, 6) / Math.pow(freq, 2); serie.add(freq, value, ""); } chart = ChartFactory.createXYLineChart("", "", "?, ", serie); } else return; chart.removeLegend(); chart.setAntiAlias(false); XYPlot plot = chart.getXYPlot(); // org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis(); // // org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis(); // yAxis.setRange(3.99, 4.01); ChartPanel chartPanel = new ChartPanel(chart); drawGraphOfEnergy(chartPanel); }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * *//*w w w . ja v a 2 s .co m*/ protected void configureChart(JFreeChart jfreeChart, JRChartPlot jrPlot) throws JRException { ChartSettings chartSettings = getChartSettings(); setChartBackground(jfreeChart); setChartTitle(jfreeChart); setChartSubtitles(jfreeChart); setChartLegend(jfreeChart); setChartBorder(jfreeChart); Boolean chartAntiAlias = chartSettings.getAntiAlias(); if (chartAntiAlias != null) jfreeChart.setAntiAlias(chartAntiAlias); Boolean textAntiAlias = chartSettings.getTextAntiAlias(); if (textAntiAlias != null) jfreeChart.setTextAntiAlias((boolean) textAntiAlias); RectangleInsets padding = chartSettings.getPadding(); if (padding != null) { jfreeChart.setPadding(padding);//FIXMETHEME consider using linebox } configurePlot(jfreeChart.getPlot(), jrPlot); }