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:ReportGen.java

private void yearlyPreview() throws NumberFormatException {
    exportcounttableexcel.setEnabled(true);
    exportcounttablepdf.setEnabled(true);

    tableModel = (DefaultTableModel) dataTable.getModel();
    tableModel.getDataVector().removeAllElements();
    tableModel.fireTableDataChanged();//from w  w w  .ja  va2 s  .c  om
    String str[] = { "Years", "Values" };
    tableModel.setColumnIdentifiers(str);
    ChartPanel chartPanel;
    displaypane.removeAll();
    displaypane.revalidate();
    displaypane.repaint();
    displaypane.setLayout(new BorderLayout());
    //row
    String series1 = "Results";
    //column
    String year[] = { "2014", "2015", "2016", "2017", "2018", "2019", "2020" };

    dataset = new DefaultCategoryDataset();
    dataset.addValue(0, series1, year[0]);
    dataset.addValue(1, series1, year[1]);
    dataset.addValue(2, series1, year[2]);
    dataset.addValue(3, series1, year[3]);
    dataset.addValue(4, series1, year[4]);
    dataset.addValue(5, series1, year[5]);
    dataset.addValue(6, series1, year[6]);

    chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title
            "Years", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // 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 org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    chartPanel = new ChartPanel(chart);
    displaypane.add(chartPanel, BorderLayout.CENTER);
}

From source file:grafici.MediciBarChart.java

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

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(titolo, // 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 = (CategoryPlot) chart.getPlot();

    // ******************************************************************
    // More than 150 demo applications are included with the JFreeChart
    // Developer Guide...for more information, see:
    //
    // > http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // set the range axis to display integers only...
    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.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));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.altaprise.vawr.charts.demos.StackedBarChartDemo4.java

/**
 * Creates a sample chart.//from w  w  w . j  a  va2s.c  o  m
 * 
 * @param dataset  the dataset for the chart.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 4", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Product 1 (US)", "G1");
    map.mapKeyToGroup("Product 1 (Europe)", "G1");
    map.mapKeyToGroup("Product 1 (Asia)", "G1");
    map.mapKeyToGroup("Product 1 (Middle East)", "G1");
    map.mapKeyToGroup("Product 2 (US)", "G2");
    map.mapKeyToGroup("Product 2 (Europe)", "G2");
    map.mapKeyToGroup("Product 2 (Asia)", "G2");
    map.mapKeyToGroup("Product 2 (Middle East)", "G2");
    map.mapKeyToGroup("Product 3 (US)", "G3");
    map.mapKeyToGroup("Product 3 (Europe)", "G3");
    map.mapKeyToGroup("Product 3 (Asia)", "G3");
    map.mapKeyToGroup("Product 3 (Middle East)", "G3");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(8, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(9, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(10, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(11, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Product 1");
    domainAxis.addSubCategory("Product 2");
    domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    return chart;

}

From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PlotCreator.java

private void formatPlot(final Plot plot) {
    plot.setBackgroundPaint(// w w  w  .j a  v a2 s .com
            new GradientPaint(0f, 0f, new Color(213, 213, 213), 0f, 0f, new Color(156, 156, 156)));
    plot.setOutlinePaint(new Color(221, 221, 221));
}

From source file:forge.toolbox.FSkin.java

public static void setGraphicsGradientPaint(final Graphics2D g2d, final float x1, final float y1,
        final SkinColor skinColor1, final float x2, final float y2, final SkinColor skinColor2) {
    g2d.setPaint(new GradientPaint(x1, y1, skinColor1.color, x2, y2, skinColor2.color));
}

From source file:edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo1.java

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*from w w  w  .  j ava 2 s.c o  m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    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);

    // renderer.setDrawOutlines(true);
    // renderer.setUseFillPaint(true);
    // renderer.setFillPaint(Color.white);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo2.java

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from   w w w  . j a  v a 2 s  .c  o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    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);
    // renderer.setDrawOutlines(true);
    // renderer.setUseFillPaint(true);
    // renderer.setFillPaint(Color.white);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    return chart;

}

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

/**
 * Creates a ContourPlot chart./* w  ww .  j a  v  a 2s  .  c om*/
 *
 * @return the chart.
 */
private JFreeChart createContourPlot() {

    final String title = "Contour Plot";
    final String xAxisLabel = "X Values";
    final String yAxisLabel = "Y Values";
    final String zAxisLabel = "Color Values";

    if (xIsDate) {
        this.xAxis = new DateAxis(xAxisLabel);
        xIsLog = false; // force axis to be linear when displaying dates
    } else {
        if (xIsLog) {
            this.xAxis = new LogarithmicAxis(xAxisLabel);
        } else {
            this.xAxis = new NumberAxis(xAxisLabel);
        }
    }

    if (yIsLog) {
        this.yAxis = new LogarithmicAxis(yAxisLabel);
    } else {
        this.yAxis = new NumberAxis(yAxisLabel);
    }

    if (zIsLog) {
        this.zColorBar = new ColorBar(zAxisLabel);
    } else {
        this.zColorBar = new ColorBar(zAxisLabel);
    }

    if (this.xAxis instanceof NumberAxis) {
        ((NumberAxis) this.xAxis).setAutoRangeIncludesZero(false);
        ((NumberAxis) this.xAxis).setInverted(xIsInverted);
    }

    this.yAxis.setAutoRangeIncludesZero(false);

    this.yAxis.setInverted(yIsInverted);

    if (!xIsDate) {
        ((NumberAxis) this.xAxis).setLowerMargin(0.0);
        ((NumberAxis) this.xAxis).setUpperMargin(0.0);
    }

    this.yAxis.setLowerMargin(0.0);
    this.yAxis.setUpperMargin(0.0);

    this.zColorBar.getAxis().setInverted(zIsInverted);
    this.zColorBar.getAxis().setTickMarksVisible(true);

    final ContourDataset data = createDataset();

    final ContourPlot plot = new ContourPlot(data, this.xAxis, this.yAxis, this.zColorBar);

    if (xIsDate) {
        ratio = Math.abs(ratio); // don't use plot units for ratios when x axis is date
    }
    plot.setDataAreaRatio(ratio);

    final JFreeChart chart = new JFreeChart(title, null, plot, false);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));

    return chart;

}

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  .c om*/
 * 
 * @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;

}

From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java

public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart3D(" ", // chart title
            "", // domain axis label
            " (.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   w  w w  . ja va2  s.c  o  m*/

    //      #44639C;

    TextTitle title = new TextTitle("  ", labelFont);
    //      Paint paint = title.getPaint();
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    // 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(2000000, 3000000);
    // target.setLabel(" ");
    // 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());
    rangeAxis.setTickLabelFont(labelFont);

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    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 / 4.0)
    // CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
    );
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}