List of usage examples for org.jfree.chart JFreeChart setBorderStroke
public void setBorderStroke(Stroke stroke)
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) { final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset, PlotOrientation.VERTICAL, true, true, false); final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setNoDataMessage("NO DATA!"); chart.setBackgroundPaint(new Color(245, 245, 255)); chart.setBorderPaint(new Color(204, 204, 204)); chart.setBorderStroke(new BasicStroke(1f)); final LegendTitle legend = chart.getLegend(); legend.setWidth(1000);/*from w w w . ja v a 2s. c o m*/ legend.setPosition(RectangleEdge.BOTTOM); final BlockBorder border = new BlockBorder(new Color(204, 204, 204)); legend.setBorder(border); final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot(); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204)); categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setDrawBarOutline(true); final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); renderer.setPositiveItemLabelPosition(itemlabelposition); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); return chart; }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Sets the colours and gradients to be used when painting the given JFreeChart. * /*from ww w .ja v a 2 s. com*/ * @param chart * The JFreeChart to make nice. */ public static void makeChartNice(JFreeChart chart) { Plot plot = chart.getPlot(); chart.setBackgroundPaint(null); chart.setBorderStroke(new BasicStroke(1f)); chart.setBorderPaint(new Color(0xDDDDDD)); chart.setBorderVisible(true); // TODO Should we add an option for subtitles, this is where it would go. // TextTitle subTitle = new TextTitle("What's up doc?", // new Font("SansSerif", Font.BOLD, 8)); // chart.addSubtitle(subTitle); // overall plot plot.setOutlinePaint(null); plot.setInsets(new RectangleInsets(0, 5, 0, 5)); // also the overall chart panel plot.setBackgroundPaint(null); plot.setDrawingSupplier(new WabitDrawingSupplier()); // legend LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setBorder(0, 0, 0, 0); legend.setBackgroundPaint(null); legend.setPadding(2, 2, 2, 2); } if (plot instanceof CategoryPlot) { CategoryPlot cplot = (CategoryPlot) plot; CategoryItemRenderer renderer = cplot.getRenderer(); if (renderer instanceof BarRenderer) { BarRenderer brenderer = (BarRenderer) renderer; brenderer.setBarPainter(new StandardBarPainter()); brenderer.setDrawBarOutline(false); brenderer.setShadowVisible(false); brenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); } else if (renderer instanceof LineAndShapeRenderer) { // it's all taken care of by WabitDrawingSupplier } else { logger.warn("I don't know how to make " + renderer + " pretty. Leaving ugly."); } cplot.setRangeGridlinePaint(Color.BLACK); cplot.setRangeGridlineStroke(GRIDLINE_STROKE); // axes for (int i = 0; i < cplot.getDomainAxisCount(); i++) { CategoryAxis axis = cplot.getDomainAxis(i); axis.setAxisLineVisible(false); } for (int i = 0; i < cplot.getRangeAxisCount(); i++) { ValueAxis axis = cplot.getRangeAxis(i); axis.setAxisLineVisible(false); } } if (plot instanceof MultiplePiePlot) { MultiplePiePlot mpplot = (MultiplePiePlot) plot; JFreeChart pchart = mpplot.getPieChart(); PiePlot3DGradient pplot = (PiePlot3DGradient) pchart.getPlot(); pplot.setBackgroundPaint(null); pplot.setOutlinePaint(null); pplot.setFaceGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); pplot.setSideGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryDataset data = mpplot.getDataset(); Color[][] colours = WabitDrawingSupplier.SERIES_COLOURS; //Set all colours for (int i = 0; i < colours.length; i++) { if (data.getColumnCount() >= i + 1) { pplot.setSectionOutlinePaint(data.getColumnKey(i), null); GradientPaint gradient = new GradientPaint(0, 0f, colours[i][0], 100, 0f, colours[i][1]); pplot.setSectionPaint(data.getColumnKey(i), gradient); gradient = new GradientPaint(0, 0f, colours[i][1], 100, 0f, colours[i][0]); pplot.setSidePaint(data.getColumnKey(i), gradient); } } } // Tweak the title font size chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(14f)); chart.getTitle().setPadding(5, 0, 5, 0); chart.setAntiAlias(true); // shrink padding chart.setPadding(new RectangleInsets(0, 0, 0, 0)); }
From source file:cl.apr.pdf.chart.BarChartAviso.java
public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) { BufferedImage bi = null;//from ww w. j ava2 s . c om try { ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme()); //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme()); /* Step - 1: Define the data for the bar chart */ DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset(); int i = 0; for (BarChartItem barChartItem : barChartItems) { if (barChartItem.getNombre().equals("-")) { my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + ""); } else my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre()); } // my_bar_chart_dataset.addValue(34, "mes", "Ene"); // my_bar_chart_dataset.addValue(25, "mes", "Feb"); // my_bar_chart_dataset.addValue(22, "mes", "Mar"); // my_bar_chart_dataset.addValue(12, "mes", "Abr"); // my_bar_chart_dataset.addValue(40, "mes", "May"); // my_bar_chart_dataset.addValue(30, "mes", "jun"); // my_bar_chart_dataset.addValue(2, "mes", "Jul"); // my_bar_chart_dataset.addValue(15, "mes", "Ago"); /* Step -2:Define the JFreeChart object to create bar chart */ //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false); JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset, PlotOrientation.VERTICAL, true, true, false); //chart.setBackgroundPaint(Color.lightGray); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer renderer = new CustomRenderer(); renderer.setSeriesPaint(0, Color.DARK_GRAY); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBackgroundPaint(Color.white); chart.setBorderStroke(null); chart.getLegend().visible = false; /* Step -3: Write the output as PNG file with bar chart information */ int width = 480; /* Width of the image */ int height = 250; /* Height of the image */ bi = chart.createBufferedImage(width, height); /* File BarChart=new File("output_chart.png"); ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); */ } catch (Exception i) { System.out.println(i); } return bi; }
From source file:action.ImageAction.java
public JFreeChart getChart() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Ford", 23.3); dataset.setValue("Chevy", 32.4); dataset.setValue("Yugo", 44.2); boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart chart = (JFreeChart) ChartFactory.createPieChart("Cars", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true);//from ww w. j a va 2 s. c o m return chart; }
From source file:org.loklak.api.vis.PieChartServlet.java
public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) { DefaultPieDataset dataset = new DefaultPieDataset(); Iterator iter = jsonData.keys(); while (iter.hasNext()) { String keyData = (String) iter.next(); Float value = Float.parseFloat(jsonData.getString(keyData)); dataset.setValue(keyData, value); }/*w w w . jav a2 s .c o m*/ boolean legend = legendBit; boolean tooltips = tooltipBit; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.BLACK); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); return chart; }
From source file:ai.susi.server.api.vis.PieChartServlet.java
public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) { DefaultPieDataset dataset = new DefaultPieDataset(); Iterator<String> iter = jsonData.keys(); while (iter.hasNext()) { String keyData = iter.next(); Float value = Float.parseFloat(jsonData.getString(keyData)); dataset.setValue(keyData, value); }// w ww . j a va2 s . co m boolean legend = legendBit; boolean tooltips = tooltipBit; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.BLACK); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true); return chart; }
From source file:org.psystems.dicom.browser.server.stat.UseagStoreChartServlet.java
public JFreeChart getChart() { PreparedStatement psSelect = null; try {//w w w .j ava2s . c om Connection connection = Util.getConnection("main", getServletContext()); long dcmSizes = 0; long imgSizes = 0; // // ALL_IMAGE_SIZE // ALL_DCM_SIZE // psSelect = connection // .prepareStatement("SELECT ID, METRIC_NAME, METRIC_DATE, METRIC_VALUE_LONG " // + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?"); psSelect = connection.prepareStatement( "SELECT SUM(METRIC_VALUE_LONG) S " + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?"); psSelect.setString(1, "ALL_DCM_SIZE"); ResultSet rs = psSelect.executeQuery(); while (rs.next()) { dcmSizes = rs.getLong("S"); } rs.close(); psSelect.setString(1, "ALL_IMAGE_SIZE"); rs = psSelect.executeQuery(); while (rs.next()) { imgSizes = rs.getLong("S"); } rs.close(); String dcmRootDir = getServletContext().getInitParameter("webdicom.dir.src"); long totalSize = new File(dcmRootDir).getTotalSpace(); //TODO ! long freeSize = new File(dcmRootDir).getFreeSpace(); long busySize = totalSize - freeSize; // System.out.println("!!! totalSize=" + totalSize + " freeSize="+freeSize); long diskEmpty = freeSize - imgSizes - dcmSizes; // double KdiskEmpty = (double)diskEmpty/(double)totalSize; // System.out.println("!!! " + KdiskEmpty); double KdiskBusi = (double) busySize / (double) totalSize * 100; // System.out.println("!!! KdiskBusi=" + KdiskBusi); double KdcmSizes = (double) dcmSizes / (double) totalSize * 100; // System.out.println("!!! KdcmSizes=" + KdcmSizes); double KimgSizes = (double) imgSizes / (double) totalSize * 100; // System.out.println("!!! KimgSizes=" + KimgSizes); double KdiskFree = (double) freeSize / (double) (totalSize - KdcmSizes - KimgSizes) * 100; // System.out.println("!!! KdiskFree=" + KdiskFree); DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("??? (DCM-) " + dcmSizes / 1000 + " .", KdcmSizes); dataset.setValue("? (JPG-) " + imgSizes / 1000 + " .", KimgSizes); dataset.setValue("? " + busySize / 1000 + " .", KdiskBusi); dataset.setValue(" " + freeSize / 1000 + " .", KdiskFree); boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart( "? ? ?? ?", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); // chart.setBorderVisible(true); // chart.setPadding(new RectangleInsets(20 ,20,20,20)); return chart; } catch (SQLException e) { logger.error(e); e.printStackTrace(); } finally { try { if (psSelect != null) psSelect.close(); } catch (SQLException e) { logger.error(e); } } return null; }
From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java
public static void customizeChart(JFreeChart jfchart, ChartParams params) { // title/* w ww . j a v a2 s.c om*/ if (params.get(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) { TextTitle title = new TextTitle(params.getString(ChartParams.TITLE_PREFIX + ChartParams.TITLE_SUFFIX)); customizeTitle(title, params, ChartParams.TITLE_PREFIX); jfchart.setTitle(title); } // subtitle if (params.get(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX) != null) { TextTitle subtitle = new TextTitle( params.getString(ChartParams.SUBTITLE_PREFIX + ChartParams.TITLE_SUFFIX)); customizeTitle(subtitle, params, ChartParams.SUBTITLE_PREFIX); jfchart.addSubtitle(subtitle); } // legend LegendTitle legend = jfchart.getLegend(); customizeLegend(legend, params); // anti-alias if (params.get(ChartParams.ANTI_ALIAS) != null) { jfchart.setAntiAlias(params.getBoolean(ChartParams.ANTI_ALIAS).booleanValue()); } // background color if (params.get(ChartParams.BACKGROUND_COLOR) != null) { jfchart.setBackgroundPaint(params.getColor(ChartParams.BACKGROUND_COLOR)); } // border if (params.get(ChartParams.BORDER_VISIBLE) != null && params.getBoolean(ChartParams.BORDER_VISIBLE).booleanValue()) { jfchart.setBorderVisible(true); if (params.get(ChartParams.BORDER_COLOR) != null) { jfchart.setBorderPaint(params.getColor(ChartParams.BORDER_COLOR)); } if (params.get(ChartParams.BORDER_STROKE) != null) { jfchart.setBorderStroke(params.getStroke(ChartParams.BORDER_STROKE)); } } }
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 ww w. j a v a 2 s . c o m*/ jfreeChart.setBorderVisible(isVisible); } }