List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of two Area Diagrams. * /* w w w . ja v a2 s. co m*/ * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param doubles * The array of values of the first array. * @param doubles2 * The array of values of the second array. * @return a chart panel with the graphical representation. */ public static ChartPanel createArea(String title, String x, String y, Double[] doubles, Double[] doubles2) { JFreeChart chart = null; if (doubles.length != doubles2.length) { System.out.println("ERROR with lengths."); } else { Double[][] data = new Double[2][doubles.length]; data[0] = doubles; data[1] = doubles2; final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Power ", "", data); chart = ChartFactory.createAreaChart(title, x, y, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // domainAxis.setTickUnit(new NumberTickUnit(10)); NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } return new ChartPanel(chart); }
From source file:barChart1.BarChartDemo.java
/** * Creates a sample chart./*from www . ja v a 2 s . com*/ * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Belgium vs Italy vs Ireland ", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(64, 0, 0)); GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createMultiplePieChart3D(CategoryDataset dataset) { MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(TableOrder.BY_COLUMN); plot.setBackgroundPaint(null);/* ww w. j av a2 s . com*/ plot.setOutlineStroke(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); pieChart.setTitle(seriesTitle); pieChart.removeLegend(); pieChart.setBackgroundPaint(null); plot.setPieChart(pieChart); if (tooltips) { PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); } if (urls) { PieURLGenerator urlGenerator = new StandardPieURLGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setURLGenerator(urlGenerator); } JFreeChart chart = new JFreeChart("MultiplePie Chart 3D Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); PiePlot piePlot = (PiePlot) pieChart.getPlot(); GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); piePlot.setSectionPaint("First", gp0); piePlot.setSectionPaint("Second", gp1); piePlot.setSectionPaint("Third", gp2); return chart; }
From source file:org.ewhoxford.swt.bloodpressure.ui.MeasurePageTab.java
/** * Creates a chart.//from www . ja v a 2 s . c om * * @param dataset * a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset, XYPlot bpMeasureXYPlot) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Blood Pressure Measure", // title "time(s)", // x-axis label "Pressure(mmHg)", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); bpMeasureXYPlot = (XYPlot) chart.getPlot(); bpMeasureXYPlot.setBackgroundPaint(Color.lightGray); bpMeasureXYPlot.setDomainGridlinePaint(Color.white); bpMeasureXYPlot.setRangeGridlinePaint(Color.white); // bpMeasureXYPlot.setAxisOffset(new RectangleInsets(300, 0, 0, // BOUNDARY_NUMBER_OF_POINTS)); // bpMeasureXYPlot.setDomainCrosshairVisible(true); // bpMeasureXYPlot.setRangeCrosshairVisible(true); XYItemRenderer r = bpMeasureXYPlot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } ValueAxis axis = bpMeasureXYPlot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); // axis.setRange(0, 1000); axis.setAutoRange(true); axis = bpMeasureXYPlot.getRangeAxis(); axis.setRange(0, 300.0); // DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); // axis.setRange(0, 1000); return chart; }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of two Area Diagrams. * /*from w w w. ja va2s . c om*/ * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param doubles * The array of values of the first array. * * @return a chart panel with the graphical representation. */ public static ChartPanel createExpectedPowerChart(String title, String x, String y, double[] data) { JFreeChart chart = null; XYSeries series1 = new XYSeries("Expected Power"); for (int i = 0; i < data.length; i++) { series1.add(i, data[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls); 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); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setVerticalTickLabels(true); domainAxis.setRange(0.0, 1440.0); domainAxis.setTickUnit(new NumberTickUnit(100)); return new ChartPanel(chart); }
From source file:org.efs.openreports.engine.ChartReportEngine.java
private static ChartEngineOutput createChartOutput(ReportChart reportChart, ChartValue[] values) { JFreeChart chart = null; switch (reportChart.getChartType()) { case ReportChart.BAR_CHART: chart = createBarChart(reportChart, values); break;/* www. ja va2s . c o m*/ case ReportChart.PIE_CHART: chart = createPieChart(reportChart, values); break; case ReportChart.XY_CHART: chart = createXYChart(reportChart, values); break; case ReportChart.TIME_CHART: chart = createTimeChart(reportChart, values); break; case ReportChart.RING_CHART: chart = createRingChart(reportChart, values); break; } if (chart == null) return null; chart.setBackgroundPaint(Color.WHITE); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); BufferedImage bufferedImage = chart.createBufferedImage(reportChart.getWidth(), reportChart.getHeight(), info); byte[] image = null; try { image = EncoderUtil.encode(bufferedImage, ImageFormat.JPEG); } catch (IOException ioe) { log.warn(ioe); } ChartEngineOutput chartOutput = new ChartEngineOutput(); chartOutput.setContent(image); chartOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_JPEG); chartOutput.setChartRenderingInfo(info); chartOutput.setChartValues(values); return chartOutput; }
From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartTemplate.java
public JFreeChart createChart() { XYPlot plot = new XYPlot(); plot.setDataset(0, this.getDataset()); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(ChartColor.WHITE); chart.setTextAntiAlias(true);/*from ww w .j a v a 2s . c o m*/ // chart.removeLegend(); return chart; }
From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java
public static void generateXYScatterPlot(String fileName, double[] x, double[] y, String title, String xLabel, String yLabel) {/* w w w . j a va 2 s . c om*/ if (x.length != y.length) { DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match"); } final XYSeries series1 = new XYSeries(title); for (int i = 0; i < x.length; i++) { series1.add(x[i], y[i]); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); final JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height); } catch (IOException e) { } }
From source file:org.jfree.chart.demo.JDBCPieChartDemo.java
public JDBCPieChartDemo(String s) { super(s);//from w ww .j av a2 s .c o m PieDataset piedataset = readData(); JFreeChart jfreechart = ChartFactory.createPieChart("JDBC Pie Chart Demo", piedataset, true, true, false); jfreechart.setBackgroundPaint(Color.yellow); PiePlot pieplot = (PiePlot) jfreechart.getPlot(); pieplot.setNoDataMessage("No data available"); ChartPanel chartpanel = new ChartPanel(jfreechart); setContentPane(chartpanel); }
From source file:org.jfree.chart.demo.XYBlockChartDemo1.java
private static JFreeChart createChart(XYZDataset xyzdataset) { NumberAxis numberaxis = new NumberAxis("X"); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setLowerMargin(0.0D);//from w w w.jav a 2s. co m numberaxis.setUpperMargin(0.0D); numberaxis.setAxisLinePaint(Color.white); numberaxis.setTickMarkPaint(Color.white); NumberAxis numberaxis1 = new NumberAxis("Y"); numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis1.setLowerMargin(0.0D); numberaxis1.setUpperMargin(0.0D); numberaxis1.setAxisLinePaint(Color.white); numberaxis1.setTickMarkPaint(Color.white); XYBlockRenderer xyblockrenderer = new XYBlockRenderer(); GrayPaintScale graypaintscale = new GrayPaintScale(-2D, 1.0D); xyblockrenderer.setPaintScale(graypaintscale); XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinesVisible(false); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setOutlinePaint(Color.blue); JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo1", xyplot); jfreechart.removeLegend(); NumberAxis numberaxis2 = new NumberAxis("Scale"); numberaxis2.setAxisLinePaint(Color.white); numberaxis2.setTickMarkPaint(Color.white); numberaxis2.setTickLabelFont(new Font("Dialog", 0, 7)); PaintScaleLegend paintscalelegend = new PaintScaleLegend(new GrayPaintScale(), numberaxis2); paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); paintscalelegend.setAxisOffset(5D); paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D)); paintscalelegend.setFrame(new BlockBorder(Color.red)); paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D)); paintscalelegend.setStripWidth(10D); paintscalelegend.setPosition(RectangleEdge.RIGHT); paintscalelegend.setBackgroundPaint(new Color(120, 120, 180)); jfreechart.addSubtitle(paintscalelegend); jfreechart.setBackgroundPaint(new Color(180, 180, 250)); return jfreechart; }