Example usage for java.awt GradientPaint GradientPaint

List of usage examples for java.awt GradientPaint GradientPaint

Introduction

In this page you can find the example usage for java.awt GradientPaint GradientPaint.

Prototype

public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2) 

Source Link

Document

Constructs a simple acyclic GradientPaint object.

Usage

From source file:com.csc.GUI.ProfileGUIPanel.java

private JFreeChart createBarChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Expenses Statistics", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from  www .  j a v  a2s.  co  m*/

    // 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);

    // 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);

    // 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);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:org.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading)", "Time in ns",
            dataset, PlotOrientation.HORIZONTAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);// w  w w .jav  a  2 s  .  c om
    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));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:com.orsonpdf.demo.PDFBarChartDemo1.java

/**
 * Creates a sample chart.//from w  w  w .j  av a2  s  .co  m
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value", dataset,
            PlotOrientation.VERTICAL, true, false, false);

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

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.yellow);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    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));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

From source file:org.jfree.chart.demo.ThumbnailDemo1.java

private static JFreeChart createChart1(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo 1", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);
    barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}"));
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D));
    return jfreechart;
}

From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java

/**
 * Paints a single bar instance.//from  w w  w.ja v  a 2 s.com
 *
 * @param g2 the graphics target.
 * @param renderer the renderer.
 * @param row the row index.
 * @param column the column index.
 * @param bar the bar
 * @param base indicates which side of the rectangle is the base of the bar.
 */
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {

    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0, c1;
    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
        c1 = c0.brighter();
    } else if (itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        c0 = gp.getColor1();
        c1 = gp.getColor2();
    } else {
        c0 = Color.blue;
        c1 = Color.blue.brighter();
    }

    // as a special case, if the bar colour has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    if (base == RectangleEdge.LEFT || base == RectangleEdge.RIGHT) {
        Rectangle2D[] regions = splitVerticalBar(bar, this.g1, this.g2, this.g3);
        GradientPaint gp = new GradientPaint((float) regions[0].getMinX(), 0.0f, c0,
                (float) regions[0].getMaxX(), 0.0f, Color.white);
        g2.setPaint(gp);
        g2.fill(regions[0]);

        gp = new GradientPaint((float) regions[1].getMinX(), 0.0f, Color.white, (float) regions[1].getMaxX(),
                0.0f, c0);
        g2.setPaint(gp);
        g2.fill(regions[1]);

        gp = new GradientPaint((float) regions[2].getMinX(), 0.0f, c0, (float) regions[2].getMaxX(), 0.0f, c1);
        g2.setPaint(gp);
        g2.fill(regions[2]);

        gp = new GradientPaint((float) regions[3].getMinX(), 0.0f, c1, (float) regions[3].getMaxX(), 0.0f, c0);
        g2.setPaint(gp);
        g2.fill(regions[3]);
    } else if (base == RectangleEdge.TOP || base == RectangleEdge.BOTTOM) {
        Rectangle2D[] regions = splitHorizontalBar(bar, this.g1, this.g2, this.g3);
        GradientPaint gp = new GradientPaint(0.0f, (float) regions[0].getMinY(), c0, 0.0f,
                (float) regions[0].getMaxX(), Color.white);
        g2.setPaint(gp);
        g2.fill(regions[0]);

        gp = new GradientPaint(0.0f, (float) regions[1].getMinY(), Color.white, 0.0f,
                (float) regions[1].getMaxY(), c0);
        g2.setPaint(gp);
        g2.fill(regions[1]);

        gp = new GradientPaint(0.0f, (float) regions[2].getMinY(), c0, 0.0f, (float) regions[2].getMaxY(), c1);
        g2.setPaint(gp);
        g2.fill(regions[2]);

        gp = new GradientPaint(0.0f, (float) regions[3].getMinY(), c1, 0.0f, (float) regions[3].getMaxY(), c0);
        g2.setPaint(gp);
        g2.fill(regions[3]);
    }

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}

From source file:org.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadIntervalBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading/Interval)",
            "Time in ns", dataset, PlotOrientation.HORIZONTAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);/*  www . j  a  va2  s.  c om*/
    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));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:org.jfree.graphics2d.demo.CanvasBarChartDemo1.java

/**
 * Creates a sample chart./*w w w. j a v  a2s.  c  o  m*/
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset);

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

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setDefaultItemLabelsVisible(true);
    renderer.setDefaultItemLabelPaint(Color.yellow);
    renderer.setDefaultPositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    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));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

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 .  j a  v  a  2 s  . c o  m*/
    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:Graphic.camion.java

private void initialiser() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int k = 0;/*from w w w . ja  v  a 2 s . c  o  m*/
    for (int j = 0; j < categories.size(); j++) {
        for (int i = 0; i < series.size(); i++) {
            dataset.addValue(valeurs.get(k), series.get(i), categories.get(j));
            k++;
        }

    }
    JFreeChart chart = ChartFactory.createBarChart(titre, // chart title
            abscisse, // domain axis label
            ordonnee, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            legende, // include legend
            true, // tooltips
            false // URL
    );

    // definition de la couleur de fond
    //chart.setBackgroundPaint(couleurFond);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    //valeur comprise entre 0 et 1 transparence de la zone graphique
    plot.setBackgroundAlpha(0.9f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // pour la couleur des barres pour chaque serie
    for (int s = 0; s < series.size(); s++) {
        GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, couleursBarres[s], 0.0f, 0.0f, new Color(0, 40, 70));
        renderer.setSeriesPaint(s, gp0);

    }

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);

    add(chartPanel);
}

From source file:net.sourceforge.subsonic.controller.UserChartController.java

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false,
            false, false);/*w  ww .ja  v  a  2  s . c  om*/

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}