List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:net.sf.jooreports.web.samples.SalesReportGenerator.java
private RenderedImage createChart(Object model) { List lines = (List) ((Map) model).get("lines"); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Iterator it = lines.iterator(); it.hasNext();) { ReportLine line = (ReportLine) it.next(); dataset.addValue(line.getValue(), "sales", line.getMonth()); }//from w w w. java 2 s .c om JFreeChart chart = ChartFactory.createBarChart("Monthly Sales", "Month", "Sales", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setTitle((String) null); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); GradientPaint paint = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); renderer.setSeriesPaint(0, paint); BufferedImage image = chart.createBufferedImage(400, 300); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { ImageIO.write(image, "png", outputStream); } catch (IOException ioException) { throw new RuntimeException("should never happen: " + ioException.getMessage()); } return image; }
From source file:org.jfree.chart.demo.SecondaryDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title.// w w w . j a v a2 s .c o m */ public SecondaryDatasetDemo1(String title) { super(title); TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); JFreeChart chart = ChartFactory.createTimeSeriesChart("Secondary Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.UmsetzungBarChart.java
protected JFreeChart createBarChart(Object dataset) { final float plotForegroundAlpha = 0.6f; JFreeChart chart = ChartFactory.createStackedBarChart3D(null, Messages.UmsetzungBarChart_1, Messages.UmsetzungBarChart_2, (CategoryDataset) dataset, PlotOrientation.HORIZONTAL, false, true, false);//from w w w . j a va 2s . c o m chart.setBackgroundPaint(Color.white); chart.getPlot().setForegroundAlpha(plotForegroundAlpha); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD); return chart; }
From source file:include.picture.MyBarChart.java
/** *? */// w w w . j a v a2 s . co m public void paint() { try { check(); CategoryDataset dataset = getDataSet(series, category, data); JFreeChart chart = ChartFactory.createBarChart3D(title, axisXLabel, axisYLabel, dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.WHITE); BarRenderer3D renderer = new BarRenderer3D(); CategoryPlot plot = chart.getCategoryPlot(); renderer.setMaxBarWidth(0.01); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("", Font.PLAIN, 15)); renderer.setItemLabelsVisible(true); renderer.setItemMargin(0.1); plot.setRenderer(renderer); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(fileName); ChartUtilities.writeChartAsJPEG(fos_jpg, 1000, chart, width, height, null); } finally { try { fos_jpg.close(); } catch (Exception e) { } } } catch (Exception e) { e.printStackTrace(); } // end of try-catch }
From source file:org.jfree.chart.demo.MultipleAxisDemo2.java
/** * Creates the demo chart./*from w w w . ja v a 2 s.c o m*/ * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 2", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // DOMAIN AXIS 2 final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(1, xAxis2); // RANGE AXIS 2 final NumberAxis yAxis2 = new NumberAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:org.jfree.chart.demo.MultipleDatasetDemo1.java
/** * Constructs a new demonstration application. * * @param title the frame title./*w w w .ja v a 2s. c o m*/ */ public MultipleDatasetDemo1(final String title) { super(title); final TimeSeriesCollection dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Dataset Demo 1", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:edu.psu.citeseerx.misc.charts.CiteChartBuilderJFree.java
protected JFreeChart buildChart(Document doc) throws SQLException { Long clusterid = doc.getClusterID(); if (clusterid == null) { return null; }/* www . j a va 2s . com*/ java.util.List<ThinDoc> citingDocs = citedao.getCitingDocuments(clusterid, 0, MAX_CITING); XYDataset dataset = collectData(citingDocs); if (dataset.getItemCount(0) <= 1) { return null; } XYBarDataset ivl_dataset = new XYBarDataset(dataset, 15.0); JFreeChart chart = ChartFactory.createXYBarChart(null, "Year", true, "Citation Count", ivl_dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); NumberAxis axis = (NumberAxis) plot.getDomainAxis(); axis.setNumberFormatOverride(NumberFormat.getIntegerInstance()); //axis.setTickUnit(new DateTickUnit(DateTickUnit.YEAR, -1)); //axis.setDateFormatOverride(new SimpleDateFormat("yyyy")); return chart; }
From source file:scheduler.benchmarker.manager.CreateStackedBarChart3D.java
public ChartPanel createChartPanel() { JFreeChart jfreechart = ChartFactory.createStackedBarChart3D(title, "Category", "Value", createDataset(), PlotOrientation.HORIZONTAL, true, true, false); jfreechart.setBackgroundPaint(new Color(214, 217, 223)); CustomBarRenderer cRenderer = new CustomBarRenderer(pluginColors); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); ValueMarker marker = new ValueMarker(dataSource.getSumTotalTime()); marker.setLabel("CLASSIFICATION FINISH"); marker.setPaint(Color.RED);//from w ww .ja v a 2 s.c o m marker.setLabelPaint(Color.RED); marker.setLabelAnchor(RectangleAnchor.TOP_LEFT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker.setLabelOffsetType(LengthAdjustmentType.EXPAND); marker.setLabelFont(new Font(Font.SERIF, Font.BOLD, 12)); categoryplot.addRangeMarker(marker, Layer.FOREGROUND); categoryplot.setFixedLegendItems(createCustomLegend()); categoryplot.setRenderer(cRenderer); cPanel = new ChartPanel(jfreechart, true); return cPanel; }
From source file:Ventanas.VentanaVerGrafico.java
private void initGUI() { try {/*from w w w . j a va 2 s . com*/ this.setLayout(null); this.setIconImage( new ImageIcon(getClass().getClassLoader().getResource("Ventanas/is_a4af.gif")).getImage()); this.setTitle("Grfica"); this.setSize(705, 580); this.getContentPane().setBackground(new java.awt.Color(204, 230, 230)); this.setLocationRelativeTo(null); this.setResizable(false); { CategoryDataset dataset = createCategoryDataset(((Vector) VentanaVerEstadisticas.datosEstadistica)); JFreeChart chart = ChartFactory.createBarChart3D("Rendimiento de los operarios", "Operarios", "", dataset, PlotOrientation.HORIZONTAL, true, true, false); chart.setBackgroundPaint(new Color(204, 230, 230)); grafica = chart.createBufferedImage(700, 500); paint(grafica.getGraphics()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:greenapi.ui.charts.LineChartPanelSupport.java
@Override public JFreeChart createChart() { this.timeSeries = new TimeSeriesCollection(); this.dataset = new TranslatingXYDataset(this.timeSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart(this.getTitle(), null, this.getAxisLabel(), this.dataset, true, true, false); chart.setBackgroundPaint(getBackground()); XYPlot xyPlot = chart.getXYPlot();// w ww . j a va 2s. co m xyPlot.setOrientation(PlotOrientation.VERTICAL); xyPlot.setBackgroundPaint(Color.WHITE); xyPlot.setDomainGridlinePaint(Color.BLACK.darker()); xyPlot.setRangeGridlinePaint(Color.BLACK.darker()); xyPlot.setAxisOffset(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D)); xyPlot.setDomainCrosshairLockedOnData(true); xyPlot.setRangeCrosshairVisible(true); chart.setAntiAlias(true); return chart; }