List of usage examples for org.jfree.chart JFreeChart setBorderPaint
public void setBorderPaint(Paint paint)
From source file:DataCharts.PieGraph.java
public static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("Data Unavailable"); plot.setCircular(false);/* w ww .ja v a 2 s. c o m*/ plot.setLabelGap(0.01); plot.setBackgroundPaint(null); chart.setBorderPaint(null); chart.setBackgroundPaint(null); return chart; }
From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java
/** * Creates the demo chart./*from w w w . ja va 2 s . co m*/ * * @return The chart. */ private static JFreeChart createChart() { XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); TextTitle subtitle = new TextTitle("Four datasets and four range axes."); chart.addSubtitle(subtitle); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); // AXIS 2 NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); // AXIS 3 NumberAxis axis3 = new NumberAxis("Range Axis 3"); axis3.setLabelPaint(Color.blue); axis3.setTickLabelPaint(Color.blue); //axis3.setPositiveArrowVisible(true); plot.setRangeAxis(2, axis3); XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 2); XYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); plot.setRenderer(2, renderer3); // AXIS 4 NumberAxis axis4 = new NumberAxis("Range Axis 4"); axis4.setLabelPaint(Color.green); axis4.setTickLabelPaint(Color.green); plot.setRangeAxis(3, axis4); XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200); plot.setDataset(3, dataset4); plot.mapDatasetToRangeAxis(3, 3); XYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.green); plot.setRenderer(3, renderer4); return chart; }
From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java
/** * Creates the demo chart./* ww w.j a v a 2 s .c om*/ * * @return The chart. */ private static JFreeChart createChart() { XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 200); JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); TextTitle subtitle = new TextTitle("Four datasets and four range axes."); chart.addSubtitle(subtitle); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); // AXIS 2 NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); XYDataset dataset2 = createDataset("Series 2", 1000.0, new Day(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); // AXIS 3 NumberAxis axis3 = new NumberAxis("Range Axis 3"); axis3.setLabelPaint(Color.blue); axis3.setTickLabelPaint(Color.blue); // axis3.setPositiveArrowVisible(true); plot.setRangeAxis(2, axis3); XYDataset dataset3 = createDataset("Series 3", 10000.0, new Day(), 170); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 2); XYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); plot.setRenderer(2, renderer3); // AXIS 4 NumberAxis axis4 = new NumberAxis("Range Axis 4"); axis4.setLabelPaint(Color.green); axis4.setTickLabelPaint(Color.green); plot.setRangeAxis(3, axis4); XYDataset dataset4 = createDataset("Series 4", 25.0, new Day(), 200); plot.setDataset(3, dataset4); plot.mapDatasetToRangeAxis(3, 3); XYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.green); plot.setRenderer(3, renderer4); return chart; }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a 3D pie chart.// w w w. j av a 2 s . c o m * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * * @return the 3D pie chart as image */ public static ImageIcon createPieChart3D(String title, PieDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getLegend().setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); chart.getLegend().setBorder(0, 0, 0, 0); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setForegroundAlpha(0.9f); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(_("No data to display.")); plot.setLabelGenerator(null); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setDarkerSides(true); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a xy area chart.//from w w w. j av a 2 s . c o m * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * @return the xy area chart as image */ public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false, false, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); XYPlot plot = chart.getXYPlot(); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setNoDataMessage(_("No data to display.")); ValueAxis domainAxis = new DateAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font")); ValueAxis rangeAxis = new NumberAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); plot.setForegroundAlpha(0.5f); return new ImageIcon(chart.createBufferedImage(width, height)); }
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 www . j a va 2 s. 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:org.gbif.portal.web.util.ChartUtils.java
/** * Writes out the image using the supplied file name. * //from w ww . jav a 2 s . co m * @param legend * @param fileName * @return */ public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) { String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName + defaultExtension; } final DefaultPieDataset data = new DefaultPieDataset(); Set<String> keys = legend.keySet(); for (String key : keys) { logger.info("Adding key : " + key); data.setValue(key, legend.get(key)); } // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false); PiePlot piePlot = (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10)); piePlot.setLabelBackgroundPaint(Color.WHITE); LegendTitle lt = chart.getLegend(); lt.setBackgroundPaint(Color.WHITE); lt.setWidth(300); lt.setBorder(0, 0, 0, 0); lt.setItemFont(new Font("Arial", Font.PLAIN, 11)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250); // draw chart.draw(g2, chartArea, null, null); try { FileOutputStream fOut = new FileOutputStream(fileToCheck); ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250); return fileToCheck.getName(); } catch (IOException e) { logger.error(e.getMessage(), e); return null; } }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Sets the colours and gradients to be used when painting the given JFreeChart. * /* w w w .ja va2 s.c o m*/ * @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: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 w ww . j av a 2 s . co m return chart; }
From source file:net.pickapack.chart.LinePlotFrame.java
/** * Create a line plot frame.//from w ww . j a v a 2s. c o m * * @param linePlot the line plot * @param width the width * @param height the height */ public LinePlotFrame(LinePlot linePlot, int width, int height) { super(linePlot.getTitle()); this.linePlot = linePlot; this.numSubPlots = linePlot.getSubLinePlots().size(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.dataSets = new ArrayList<TimeSeriesCollection>(); this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>(); for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) { TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection(); this.dataSets.add(dataSetsPerSubPlot); HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>(); this.dataSinks.add(dataSinksPerSubPlot); for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) { TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle()); dataSetsPerSubPlot.addSeries(timeSeries); dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback()); } NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY()); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(3600000.0); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); DataSink dataSink = new DataSink(); new Thread(dataSink).start(); }