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:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createBarChart3D(CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    BarRenderer3D renderer = new BarRenderer3D();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }//from   w w  w  .  j  a v a2  s.  c om
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        // change rendering order to ensure that bar overlapping is the
        // right way around
        plot.setRowRenderingOrder(SortOrder.DESCENDING);
        plot.setColumnRenderingOrder(SortOrder.DESCENDING);
    }
    plot.setForegroundAlpha(0.75f);

    JFreeChart chart = new JFreeChart("Bar Chart 3D Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    plot.setForegroundAlpha(0.5f);

    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

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

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param chart/*ww  w.  j  a  v  a2s .  c om*/
 * @return
 */
private static XYBarRenderer getTimeSeriesBarRenderer(final AbstractChart chart) {

    final XYBarRenderer renderer = new XYBarRenderer();
    renderer.setMargin(0.2);

    for (int i = 0; i < chart.getColors().size(); i++) {

        final Color c = chart.getColors().get(i);
        renderer.setSeriesPaint(i, new GradientPaint(0f, 0f, c, 0f, 0f, c.brighter().brighter()));
        renderer.setSeriesOutlinePaint(i, c);

    }
    return renderer;
}

From source file:net.sourceforge.atunes.kernel.controllers.stats.StatsDialogController.java

private void setSongsChart() {
    DefaultCategoryDataset dataset = getDataSet(HandlerProxy.getRepositoryHandler().getMostPlayedSongs(10));
    JFreeChart chart = ChartFactory.createStackedBarChart3D(LanguageTool.getString("SONG_MOST_PLAYED"), null,
            null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
    chart.getTitle().setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    chart.setBackgroundPaint(new GradientPaint(0, 0, ColorDefinitions.GENERAL_NON_PANEL_TOP_GRADIENT_COLOR, 0,
            200, ColorDefinitions.GENERAL_NON_PANEL_BOTTOM_GRADIENT_COLOR));
    chart.setPadding(new RectangleInsets(5, 0, 0, 0));
    NumberAxis axis = new NumberAxis();
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setTickLabelFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    chart.getCategoryPlot().setRangeAxis(axis);
    chart.getCategoryPlot().setForegroundAlpha(0.6f);
    chart.getCategoryPlot().getRenderer().setPaint(Color.GREEN);

    ((StatsDialog) frameControlled).getSongsChart().setIcon(new ImageIcon(chart.createBufferedImage(710, 250)));
}

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

/**
 * Creates and returns a sample stacked horizontal bar chart.
 *
 * @return a sample stacked horizontal bar chart.
 *///from   w  w  w.ja  va  2s  . c  o  m
public JFreeChart createStackedHorizontalBarChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("bar.horizontal-stacked.title");
    final String domain = this.resources.getString("bar.horizontal-stacked.domain");
    final String range = this.resources.getString("bar.horizontal-stacked.range");

    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final JFreeChart chart = ChartFactory.createStackedBarChart(title, domain, range, data,
            PlotOrientation.HORIZONTAL, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));
    return chart;

}

From source file:jmeanshift.ChartProof.java

private void bubblyBubblesScatter(JPanel panel) {

    JFreeChart chart = ChartFactory.createScatterPlot(TITLE, "X1", "X2", dataset, PlotOrientation.VERTICAL,
            true, true, false);//from  w w  w.ja  v  a  2s  .  c o  m

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.yellow));

    plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.CYAN);
    plot.setForegroundAlpha(0.65f);

    domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setLowerBound(0);
    domainAxis.setUpperBound(255);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis = (NumberAxis) plot.getRangeAxis();

    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(255);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel = new ChartPanel(chart);
    chartPanel.addChartMouseListener(this);
    panel.setLayout(new GridLayout(0, 1));
    panel.add(chartPanel);

}

From source file:RDGraphGenerator.java

private JFreeChart createTimeChart(String riderID) {

    String riderName = (String) riders.get(riderID);
    final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Hours", // chart title
            "Month", // domain axis label
            "Hours", // range axis label
            (CategoryDataset) riderTimes.get(riderID), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );/*from   w ww .j  a  v a  2  s.  c  o  m*/

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("0", "G1");
    map.mapKeyToGroup("1", "G1");
    map.mapKeyToGroup("2", "G1");
    map.mapKeyToGroup("3", "G1");
    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);

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

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

    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.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    CategoryAxis ca = plot.getDomainAxis();
    ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    //Make around the chart transparent.
    chart.setBackgroundPaint(null);
    return chart;

}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createLineChart3D(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart3D("Line Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*  w w w .jav a  2 s .  c om*/

    chart.setBackgroundPaint(Color.white);

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

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LineRenderer3D renderer = (LineRenderer3D) plot.getRenderer();

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

    GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.orange, 0.0f, 0.0f, new Color(0, 64, 64));
    renderer.setWallPaint(gp);

    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart.java

/**
 * Creates a chart.//from w  ww .j  av  a 2s  .  co m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, //"Bar Chart Demo",         // chart title
            domainLabel, //"Category",               // domain axis label
            rangeLabel, //"Value",                  // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // 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 = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // 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.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java

/**
 * Draw a GraphNode as a rectangle with a name
 *
 * @param g   The Java2D Graphics/*www .  ja v  a 2s . c om*/
 * @param col The color to draw
 */
public void drawNode(final Graphics2D g, final Color col) {
    final int x = displayPosition.x;
    final int y = displayPosition.y;

    g.setFont(g.getFont().deriveFont(Font.BOLD, 11));
    final FontMetrics metrics = g.getFontMetrics();
    final String name = node.getId();
    final Rectangle2D rect = metrics.getStringBounds(name, g);
    final int stringWidth = (int) rect.getWidth();
    setSize(Math.max(stringWidth, 50) + 10, 25);

    int step = 4;
    int alpha = 96;
    for (int i = 0; i < step; ++i) {
        g.setColor(new Color(0, 0, 0, alpha - (32 * i)));
        g.drawLine(x + i + 1, y + nodeHeight + i, x + nodeWidth + i - 1, y + nodeHeight + i);
        g.drawLine(x + nodeWidth + i, y + i, x + nodeWidth + i, y + nodeHeight + i);
    }

    Shape clipShape = new Rectangle(x, y, nodeWidth, nodeHeight);

    g.setComposite(AlphaComposite.SrcAtop);
    g.setPaint(new GradientPaint(x, y, col, x + nodeWidth, y + nodeHeight, col.darker()));
    g.fill(clipShape);

    g.setColor(Color.blue);
    g.draw3DRect(x, y, nodeWidth - 1, nodeHeight - 1, true);

    g.setColor(Color.BLACK);
    g.drawString(name, x + (nodeWidth - stringWidth) / 2, y + 15);
}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java

private static JFreeChart createStackedBarChart(CategoryDataset dataset) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);

    StackedBarRenderer renderer = new StackedBarRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }//from w ww .jav a  2s  .  com
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart("StackedBar Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setDrawBarOutline(false);

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

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;

}