Example usage for org.jfree.chart.plot Plot setDrawingSupplier

List of usage examples for org.jfree.chart.plot Plot setDrawingSupplier

Introduction

In this page you can find the example usage for org.jfree.chart.plot Plot setDrawingSupplier.

Prototype

public void setDrawingSupplier(DrawingSupplier supplier) 

Source Link

Document

Sets the drawing supplier for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Sets the colours and gradients to be used when painting the given JFreeChart.
 * //ww  w.ja v a  2s. c om
 * @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:guineu.modules.visualization.intensityplot.IntensityPlotFrame.java

public IntensityPlotFrame(ParameterSet parameters) {
    super("", true, true, true, true);

    String title = "Intensity plot [" + GuineuCore.getDesktop().getSelectedDataFiles()[0].getDatasetName()
            + "]";
    String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString();

    // create dataset
    dataset = new IntensityPlotDataset(parameters);

    // create new JFreeChart
    logger.finest("Creating new chart instance");

    chart = ChartFactory.createLineChart(title, xAxisLabel, "Height", dataset, PlotOrientation.VERTICAL, true,
            true, false);/*from   ww w  .jav  a 2s .c  o m*/

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set renderer
    StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true);
    renderer.setBaseStroke(new BasicStroke(2));
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.white);

    // set tooltip generator
    CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
    renderer.setBaseToolTipGenerator(toolTipGenerator);

    CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);

    IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this);
    add(toolBar, BorderLayout.EAST);

    // disable maximum size (we don't want scaling)
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setBorder(0, 0, 0, 0);

    Plot dplot = chart.getPlot();

    // set shape provider
    IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier();
    dplot.setDrawingSupplier(shapeSupplier);

    // set y axis properties
    NumberAxis yAxis;

    yAxis = (NumberAxis) ((CategoryPlot) dplot).getRangeAxis();

    NumberFormat yAxisFormat = new DecimalFormat("0.0E0");
    yAxis.setNumberFormatOverride(yAxisFormat);

    setTitle(title);
    setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
    setBackground(Color.white);
    pack();

}

From source file:net.sf.clichart.chart.AbstractChartBuilder.java

private void setOptions(JFreeChart chart, Options options) {
    setAxisLimits(chart.getXYPlot().getRangeAxis(), options.getMinYValue(), options.getMaxYValue(),
            options.forceYRange());//  w w  w . ja va  2  s  .  c  o m

    setAxisRenderer(chart.getXYPlot(), 0, options.isBarChart(), options.hasDataPoints(),
            options.getLineWeight());

    if (options.getColourOverrides() != null) {
        Plot plot = chart.getPlot();
        DrawingSupplierWrapper drawingSupplierWrapper = new DrawingSupplierWrapper();
        drawingSupplierWrapper.addColourOverrides(options.getColourOverrides());
        plot.setDrawingSupplier(drawingSupplierWrapper);
    }
}

From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java

private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String uri = request.getRequestURI();
    String requestString = uri.split("test_images/")[1];
    String[] requestParams = requestString.split("/");

    String reportName = URLDecoder.decode(requestParams[0], charset);
    String categoryName = URLDecoder.decode(requestParams[1], charset);
    // String className = URLDecoder.decode(requestParams[2], charset);
    String testName = URLDecoder.decode(requestParams[3], charset);
    String agent = URLDecoder.decode(requestParams[4], charset);

    ReportDatabase db = ReportDatabase.getInstance();
    Report report = db.getReport(reportName);
    List<Category> categories = report.getCategories();
    Category category = getCategoryByName(categories, categoryName);
    List<Benchmark> benchmarks = category.getBenchmarks();
    Benchmark benchmark = getBenchmarkByName(benchmarks, testName);
    List<Result> results = benchmark.getResults();
    Result result = getResultsByAgent(results, agent);

    String title = BrowserInfo.getBrowser(agent);
    JFreeChart chart = createChart(testName, result, title, results);

    chart.getTitle().setFont(Font.decode("Verdana BOLD 12"));
    chart.setAntiAlias(true);/*w w w  .  ja va  2s  .  co m*/
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(new Color(241, 241, 241));

    Plot plot = chart.getPlot();

    plot.setDrawingSupplier(getDrawingSupplier());
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 640, 480, new Color(200, 200, 200)));

    if (plot instanceof XYPlot) {
        XYPlot xyplot = (XYPlot) plot;
        Font labelFont = Font.decode("Verdana PLAIN");
        xyplot.getDomainAxis().setLabelFont(labelFont);
        xyplot.getRangeAxis().setLabelFont(labelFont);
        org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
        xyitemrenderer.setStroke(new BasicStroke(4));
        if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
            xylineandshaperenderer.setShapesVisible(true);
            xylineandshaperenderer.setShapesFilled(true);
        }
    }

    // Try to fit all the graphs into a 1024 window, with a min of 240 and a max
    // of 480
    final int graphWidth = Math.max(240, Math.min(480, (1024 - 10 * results.size()) / results.size()));
    BufferedImage img = chart.createBufferedImage(graphWidth, 240);
    byte[] image = EncoderUtil.encode(img, ImageFormat.PNG);

    // The images have unique URLs; might as well set them to never expire.
    response.setHeader("Cache-Control", "max-age=0");
    response.setHeader("Expires", "Fri, 2 Jan 1970 00:00:00 GMT");
    response.setContentType("image/png");
    response.setContentLength(image.length);

    OutputStream output = response.getOutputStream();
    output.write(image);
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
    plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
    plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());

    plot.setNoDataMessage(chartDefinition.getNoDataMessage());

    // create a custom palette if it was defined
    if (chartDefinition.getPaintSequence() != null) {
        DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(),
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
        plot.setDrawingSupplier(drawingSupplier);
    }// w  w  w. j  a  v a  2s . c  om
    plot.setOutlineStroke(null); // TODO define outline stroke

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
        CategoryAxis domainAxis = categoryPlot.getDomainAxis();
        if (domainAxis != null) {
            domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
            domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
            if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
                domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
            }
            domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
        }
        NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
        if (numberAxis != null) {
            numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
            numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
            if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
            }
            if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
            }

            if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
            }
            if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
                numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
            }
            if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
            }
        }

    }
    if (plot instanceof PiePlot) {
        PiePlot pie = (PiePlot) plot;
        PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
        pie.setInteriorGap(pieDefinition.getInteriorGap());
        pie.setStartAngle(pieDefinition.getStartAngle());
        pie.setLabelFont(pieDefinition.getLabelFont());
        if (pieDefinition.getLabelPaint() != null) {
            pie.setLabelPaint(pieDefinition.getLabelPaint());
        }
        pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
        if (pieDefinition.isLegendIncluded()) {
            StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
            pie.setLegendLabelGenerator(labelGen);
        }
        if (pieDefinition.getExplodedSlices() != null) {
            for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext();) {
                pie.setExplodePercent((Comparable) iter.next(), .30);
            }
        }
        pie.setLabelGap(pieDefinition.getLabelGap());
        if (!pieDefinition.isDisplayLabels()) {
            pie.setLabelGenerator(null);
        } else {
            if (pieDefinition.isLegendIncluded()) {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            } else {
                StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
                        "{0} = {1} ({2})"); //$NON-NLS-1$
                pie.setLabelGenerator(labelGen);
            }
        }
    }
    if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot pies = (MultiplePiePlot) plot;
        CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
        pies.setDataset(categoryDatasetChartDefintion);
    }
    if (plot instanceof MeterPlot) {
        MeterPlot meter = (MeterPlot) plot;
        DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
        List intervals = widget.getIntervals();
        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            MeterInterval interval = (MeterInterval) intervalIterator.next();
            meter.addInterval(interval);
        }

        meter.setNeedlePaint(widget.getNeedlePaint());
        meter.setDialShape(widget.getDialShape());
        meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
        meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));

    }
    if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
            XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
                }
                if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
            TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (domainAxis instanceof DateAxis) {
                    DateAxis da = (DateAxis) domainAxis;
                    if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
                        da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
                    }
                    if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
                        da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
                    }
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
                if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
                }
            }
        } else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
            XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
            xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            if (domainAxis != null) {
                domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
                domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
                domainAxis
                        .setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
                if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
                    ((NumberAxis) domainAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
                    domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
                }
            }

            ValueAxis rangeAxis = xyPlot.getRangeAxis();
            if (rangeAxis != null) {
                rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
                rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
                rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
                    rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
                    rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
                    ((NumberAxis) rangeAxis)
                            .setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
                }
                if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
                    rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
                }
            }

        }
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

protected void setChartStyles(JFreeChart chart, UIChart comp) {
    Plot plot = chart.getPlot();

    RectangleInsets insets = plot.getInsets();
    Double tm = comp.getTopMargin();
    Double lm = comp.getLeftMargin();
    Double bm = comp.getBottomMargin();
    Double rm = comp.getRightMargin();
    if (tm == null || tm < 0)
        tm = insets.getTop();//from   w ww  .  j  a va 2 s  .co  m
    if (lm == null || lm < 0)
        lm = insets.getLeft();
    if (bm == null || bm < 0)
        bm = insets.getBottom();
    if (rm == null || rm < 0)
        rm = insets.getRight();
    plot.setInsets(new RectangleInsets(tm, lm, bm, rm));

    Paint color = comp.getBackgroundColor();
    if (color != null) {
        chart.setBackgroundPaint(color);
    }

    Image image = loadImage(comp.getBackgroundImage());
    if (image != null) {
        chart.setBackgroundImage(image);
        chart.setBackgroundImageAlignment(getImageAlign(comp.getBackgroundImagePosition()));
        chart.setBackgroundImageAlpha(comp.getBackgroundImageAlpha());
    }

    color = comp.getPlotColor();
    if (color != null) {
        plot.setBackgroundPaint(color);
    }

    Float alpha;
    if ((alpha = comp.getBackgroundAlpha()) != null) {
        plot.setBackgroundAlpha(alpha);
    }
    if ((alpha = comp.getForegroundAlpha()) != null) {
        plot.setForegroundAlpha(alpha);
    }

    image = loadImage(comp.getPlotImage());
    if (image != null) {
        plot.setBackgroundImage(image);
        plot.setBackgroundImageAlignment(getImageAlign(comp.getPlotImagePosition()));
        plot.setBackgroundImageAlpha(comp.getBackgroundImageAlpha());
    }

    Paint[] colorPalette = comp.getColorPalette();
    if (colorPalette != null) {
        plot.setDrawingSupplier(new CustomDrawingSupplier(colorPalette));
    } else {
        plot.setDrawingSupplier(new CustomDrawingSupplier());
    }
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setPlotDrawingDefaults(Plot p, JRChartPlot jrPlot) {
    PlotSettings plotSettings = getPlotSettings();
    Paint[] paintSequence = getPaintSequence(plotSettings, jrPlot);
    Paint[] outlinePaintSequence = getOutlinePaintSequence(plotSettings);
    Stroke[] strokeSequence = getStrokeSequence(plotSettings);
    Stroke[] outlineStrokeSequence = getOutlineStrokeSequence(plotSettings);

    //      Shape[] defaultPlotShapeSequence = 
    //         getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_SHAPE_SEQUENCE) != null ?
    //         (Shape[])getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_SHAPE_SEQUENCE) :
    //         DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;

    p.setDrawingSupplier(new DefaultDrawingSupplier(paintSequence, outlinePaintSequence, strokeSequence,
            outlineStrokeSequence, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *//*from   w  ww.  j  av a 2 s  . co  m*/
protected void configurePlot(Plot plot) {
    plot.setOutlinePaint(null);

    if (getPlot().getOwnBackcolor() == null)// in a way, plot backcolor inheritence from chart is useless
    {
        plot.setBackgroundPaint(null);
    } else {
        plot.setBackgroundPaint(getPlot().getBackcolor());
    }

    float backgroundAlpha = getPlot().getBackgroundAlphaFloat() == null ? 1f
            : getPlot().getBackgroundAlphaFloat();
    float foregroundAlpha = getPlot().getForegroundAlphaFloat() == null ? 1f
            : getPlot().getForegroundAlphaFloat();
    plot.setBackgroundAlpha(backgroundAlpha);
    plot.setForegroundAlpha(foregroundAlpha);

    if (plot instanceof CategoryPlot) {
        // Handle rotation of the category labels.
        CategoryAxis axis = ((CategoryPlot) plot).getDomainAxis();
        // it's OK to use deprecated method here; avoiding it means attempting cast operations  
        double labelRotation = getLabelRotation();
        if (labelRotation == 90) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
        } else if (labelRotation == -90) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        } else if (labelRotation < 0) {
            axis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI));
        } else if (labelRotation > 0) {
            axis.setCategoryLabelPositions(
                    CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI));
        }
    }

    // Set any color series
    SortedSet<JRSeriesColor> seriesColors = getPlot().getSeriesColors();
    if (seriesColors != null && seriesColors.size() > 0) {
        if (seriesColors.size() == 1) {
            // Add the single color to the beginning of the color cycle, using all the default
            // colors.  To replace the defaults you have to specify at least two colors.
            Paint[] colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + 1];
            colors[0] = seriesColors.first().getColor();
            System.arraycopy(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, 0, colors, 1,
                    DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length);
            plot.setDrawingSupplier(
                    new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
        } else if (seriesColors.size() > 1) {
            // Set up a custom drawing supplier that cycles through the user's colors
            // instead of the default colors.
            Color[] colors = new Color[seriesColors.size()];
            JRSeriesColor[] colorSequence = new JRSeriesColor[seriesColors.size()];
            seriesColors.toArray(colorSequence);
            for (int i = 0; i < colorSequence.length; i++) {
                colors[i] = colorSequence[i].getColor();
            }

            plot.setDrawingSupplier(
                    new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
        }
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setPlotDrawingDefaults(Plot p, JRChartPlot jrPlot) {
    List defaultSeriesColors = (List) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SERIES_COLORS);
    Paint[] defaultPlotOutlinePaintSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_OUTLINE_PAINT_SEQUENCE) != null
                    ? (Paint[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_OUTLINE_PAINT_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE;

    Stroke[] defaultPlotStrokeSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_STROKE_SEQUENCE) != null
                    ? (Stroke[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_STROKE_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE;

    Stroke[] defaultPlotOutlineStrokeSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_OUTLINE_STROKE_SEQUENCE) != null
                    ? (Stroke[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_OUTLINE_STROKE_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE;

    Shape[] defaultPlotShapeSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_SHAPE_SEQUENCE) != null
                    ? (Shape[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_SHAPE_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;
    // Set color series
    Paint[] colors = null;//from w w  w  . ja  v a2  s  .  c  o m
    SortedSet seriesColors = jrPlot.getSeriesColors();
    Paint[] colorSequence = null;
    if (seriesColors != null && seriesColors.size() > 0) {
        int seriesColorsSize = seriesColors.size();

        colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + seriesColorsSize];

        JRSeriesColor[] jrColorSequence = new JRSeriesColor[seriesColorsSize];
        seriesColors.toArray(jrColorSequence);
        colorSequence = new Paint[seriesColorsSize];

        for (int i = 0; i < seriesColorsSize; i++) {
            colorSequence[i] = jrColorSequence[i].getColor();
        }
        populateSeriesColors(colors, colorSequence);
    } else if (defaultSeriesColors != null && defaultSeriesColors.size() > 0) {
        colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + defaultSeriesColors.size()];
        colorSequence = new Paint[defaultSeriesColors.size()];
        defaultSeriesColors.toArray(colorSequence);
        populateSeriesColors(colors, colorSequence);
    } else {
        colors = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE;
    }

    p.setDrawingSupplier(new DefaultDrawingSupplier(colors, defaultPlotOutlinePaintSequence,
            defaultPlotStrokeSequence, defaultPlotOutlineStrokeSequence, defaultPlotShapeSequence));

}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setPlotDrawingDefaults(Plot p, JRChartPlot jrPlot) {
    @SuppressWarnings("unchecked")
    List<Paint> defaultSeriesColors = (List<Paint>) getDefaultValue(defaultChartPropertiesMap,
            ChartThemesConstants.SERIES_COLORS);
    Paint[] defaultPlotOutlinePaintSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_OUTLINE_PAINT_SEQUENCE) != null
                    ? (Paint[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_OUTLINE_PAINT_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE;

    Stroke[] defaultPlotStrokeSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_STROKE_SEQUENCE) != null
                    ? (Stroke[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_STROKE_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE;

    Stroke[] defaultPlotOutlineStrokeSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_OUTLINE_STROKE_SEQUENCE) != null
                    ? (Stroke[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_OUTLINE_STROKE_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE;

    Shape[] defaultPlotShapeSequence = getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_SHAPE_SEQUENCE) != null
                    ? (Shape[]) getDefaultValue(defaultPlotPropertiesMap,
                            ChartThemesConstants.PLOT_SHAPE_SEQUENCE)
                    : DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE;
    // Set color series
    Paint[] colors = null;/*from www  . j a  va2 s  .c  o m*/
    SortedSet<JRSeriesColor> seriesColors = jrPlot.getSeriesColors();
    Paint[] colorSequence = null;
    if (seriesColors != null && seriesColors.size() > 0) {
        int seriesColorsSize = seriesColors.size();

        colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + seriesColorsSize];

        JRSeriesColor[] jrColorSequence = new JRSeriesColor[seriesColorsSize];
        seriesColors.toArray(jrColorSequence);
        colorSequence = new Paint[seriesColorsSize];

        for (int i = 0; i < seriesColorsSize; i++) {
            colorSequence[i] = jrColorSequence[i].getColor();
        }
        populateSeriesColors(colors, colorSequence);
    } else if (defaultSeriesColors != null && defaultSeriesColors.size() > 0) {
        colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + defaultSeriesColors.size()];
        colorSequence = new Paint[defaultSeriesColors.size()];
        defaultSeriesColors.toArray(colorSequence);
        populateSeriesColors(colors, colorSequence);
    } else {
        colors = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE;
    }

    p.setDrawingSupplier(new DefaultDrawingSupplier(colors, defaultPlotOutlinePaintSequence,
            defaultPlotStrokeSequence, defaultPlotOutlineStrokeSequence, defaultPlotShapeSequence));

}