List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:org.jfree.chart.demo.BoxAndWhiskerChartDemo1.java
private static JFreeChart createChart(BoxAndWhiskerCategoryDataset boxandwhiskercategorydataset) { JFreeChart jfreechart = ChartFactory.createBoxAndWhiskerChart("Box and Whisker Chart Demo 1", "Category", "Value", boxandwhiskercategorydataset, true); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); jfreechart.setBackgroundPaint(Color.white); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.white); categoryplot.setDomainGridlinesVisible(true); categoryplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
From source file:org.jfree.chart.demo.XYDrawableAnnotationDemo1.java
private static JFreeChart createBarChart() { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); defaultcategorydataset.addValue(10D, "R1", "Q1"); defaultcategorydataset.addValue(7D, "R1", "Q2"); defaultcategorydataset.addValue(8D, "R1", "Q3"); defaultcategorydataset.addValue(4D, "R1", "Q4"); defaultcategorydataset.addValue(10.6D, "R2", "Q1"); defaultcategorydataset.addValue(6.0999999999999996D, "R2", "Q2"); defaultcategorydataset.addValue(8.5D, "R2", "Q3"); defaultcategorydataset.addValue(4.2999999999999998D, "R2", "Q4"); JFreeChart jfreechart = ChartFactory.createBarChart("Sales 2008", null, null, defaultcategorydataset, PlotOrientation.VERTICAL, false, false, false); jfreechart.setBackgroundPaint(null); jfreechart.getPlot().setBackgroundPaint(new Color(200, 200, 255, 60)); return jfreechart; }
From source file:com.church.tools.ChartTools.java
/** * Generate line chart.// ww w .j a v a 2 s . co m * * @param title the title * @param values the values * @param captions the captions * @param width the width * @param height the height * @param color the color * * @return the buffered image */ public static BufferedImage GenerateLineChart(String title, double[] values, String[] captions, int width, int height, Color color) { BufferedImage bufferedImage = null; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < values.length; i++) { dataset.addValue(values[i], "Balance Timeline", String.valueOf(i + 1)); } JFreeChart chart = ChartFactory.createLineChart(title, "Balance Timeline", "Amount", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(color); bufferedImage = chart.createBufferedImage(width, height); return bufferedImage; }
From source file:st.jigasoft.dbutil.util.ReportTheme.java
public static void crescentTheme(JFreeChart chart, String... lineNames) { XYPlot plot = (XYPlot) chart.getPlot(); chart.setBackgroundPaint(Color.white); 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(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; //renderer.setBaseShapesVisible(true); renderer.setStroke(new BasicStroke(3)); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); }// w ww. java2s .c o m DateAxis axis = (DateAxis) plot.getDomainAxis(); /* chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.decode("#121E31"), new Point(400, 200), Color.DARK_GRAY)); plot.setBackgroundPaint(null); //plot.setInteriorGap(0.04); plot.setOutlineVisible(false); int iCount = 0; // use gradients and white borders for the section colours for(Object s : lineNames) { // plot.setDomainGridlinePaint(new PrintColorUIResource(25, Color.CYAN)));//s.toString(), createGradientPaint(new Color(200, 200, 255), colorItems(iCount ++))); if(iCount == MAX_COLUNS_COLOR) iCount = 0; } // // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); */ }
From source file:org.gaixie.micrite.jfreechart.style.BarStyle.java
/** * ???/*from w ww . ja v a 2s . co m*/ * @param chart JFreeChart */ public static void styleOne(JFreeChart chart) { CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); CategoryDataset dca = categoryplot.getDataset(); //? chart.setBackgroundPaint(null); if (dca != null) { BarRenderer categoryitemrenderer = (BarRenderer) categoryplot.getRenderer(); // ? categoryitemrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // categoryitemrenderer.setBaseItemLabelFont( // new Font("", Font.PLAIN, 15)); categoryitemrenderer.setBaseItemLabelsVisible(true); //tooltip categoryplot.getRenderer() .setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{0}={2}", new DecimalFormat())); //? for (int i = 0; i < dca.getRowCount(); i++) { int colorIdx = i % colors.length; categoryitemrenderer.setSeriesPaint(i, colors[colorIdx]); } } else { //? categoryplot.setNoDataMessage("NO DATA"); } }
From source file:com.etest.view.tq.charts.SubjectTestLineChart.java
public static JFreeChart difficultIndex(int tqCoverageId) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) { dataset.setValue((int) (ci.getDifficultIndex() * 100), "Difficulty Index", String.valueOf(ci.getItemNo())); }/*from w w w. ja v a 2 s . com*/ JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.", "Difficulty Index (%)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setFillPaint(Color.white); return chart; }
From source file:com.thalesgroup.hudson.plugins.sourcemonitor.SourceMonitorChartBuilder.java
public static JFreeChart buildChart(SourceMonitorBuildAction action) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of errors", buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null);/*w w w .j a v a 2 s. co m*/ plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer(); SourceMonitorRenderer renderer = new SourceMonitorRenderer(action.getUrlName()); plot.setRenderer(firstRender); return chart; }
From source file:org.jfree.chart.demo.XYLineAndShapeRendererDemo2.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset(1, 1.0D); JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 2", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "This chart shows various combinations of the useFillPaint and useOutlinePaint flags."); texttitle.setFont(new Font("Dialog", 0, 10)); jfreechart.addSubtitle(texttitle);//from w ww . j a v a 2s . c om XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 8D, 8D); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setSeriesShape(0, double1); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer.setSeriesOutlinePaint(0, Color.gray); XYDataset xydataset1 = createDataset(2, 2D); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); xyplot.setDataset(1, xydataset1); xyplot.setRenderer(1, xylineandshaperenderer1); xylineandshaperenderer1.setSeriesShape(0, double1); xylineandshaperenderer1.setSeriesPaint(0, Color.red); xylineandshaperenderer1.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer1.setUseFillPaint(true); XYDataset xydataset2 = createDataset(3, 3D); XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); xyplot.setDataset(2, xydataset2); xyplot.setRenderer(2, xylineandshaperenderer2); xylineandshaperenderer2.setSeriesShape(0, double1); xylineandshaperenderer2.setSeriesPaint(0, Color.red); xylineandshaperenderer2.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer2.setUseOutlinePaint(true); XYDataset xydataset3 = createDataset(4, 4D); XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer(); xyplot.setDataset(3, xydataset3); xyplot.setRenderer(3, xylineandshaperenderer3); xylineandshaperenderer3.setSeriesShape(0, double1); xylineandshaperenderer3.setSeriesPaint(0, Color.red); xylineandshaperenderer3.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer3.setUseOutlinePaint(true); xylineandshaperenderer3.setUseFillPaint(true); XYDataset xydataset4 = createDataset(5, 5D); XYLineAndShapeRenderer xylineandshaperenderer4 = new XYLineAndShapeRenderer(); xyplot.setDataset(4, xydataset4); xyplot.setRenderer(4, xylineandshaperenderer4); xylineandshaperenderer4.setSeriesShape(0, double1); xylineandshaperenderer4.setSeriesPaint(0, Color.red); xylineandshaperenderer4.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer4.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer4.setUseOutlinePaint(true); xylineandshaperenderer4.setUseFillPaint(true); xylineandshaperenderer4.setDrawOutlines(false); return jfreechart; }
From source file:com.orsonpdf.demo.PDFPieChartDemo1.java
/** * Creates a chart.//from w w w .jav a2s . c o m * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", dataset, false, false, false); chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); plot.setShadowPaint(null); plot.setLabelShadowPaint(null); // use gradients and white borders for the section colours plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED)); plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 1.0f); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:com.etest.view.tq.charts.SubjectTestLineChart.java
public static JFreeChart discriminationIndex(int tqCoverageId) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) { dataset.setValue((int) (ci.getDiscriminationIndex() * 100), "Discrimination Index", String.valueOf(ci.getItemNo())); }/*ww w . j a v a 2s. c o m*/ JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.", "Discrimination Index (%)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setFillPaint(Color.white); return chart; }