List of usage examples for org.jfree.chart.ui Layer BACKGROUND
Layer BACKGROUND
To view the source code for org.jfree.chart.ui Layer BACKGROUND.
Click Source Link
From source file:org.mars_sim.msp.ui.swing.demo.BarChartDemo7.java
/** * Creates a sample chart./*from w w w. j a v a 2 s .co m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 7", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // 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... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final IntervalMarker target = new IntervalMarker(4.5, 7.5); target.setLabel("Target Range"); target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); target.setLabelAnchor(RectangleAnchor.LEFT); target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); target.setPaint(new Color(222, 222, 255, 128)); plot.addRangeMarker(target, Layer.BACKGROUND); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); //renderer.setItemMargin(0.10); renderer.setMaximumBarWidth(.5); // set maximum width to 35% of chart // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); // renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator()); renderer.setDefaultItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0); renderer.setDefaultPositiveItemLabelPosition(p); final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0); renderer.setPositiveItemLabelPositionFallback(p2); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }