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

protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) {
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout subLayout = new TextLayout(s, mFont, frc);
    float advance = subLayout.getAdvance();

    GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2);
    g2.setPaint(gradient);/*from w  w w. j  a va2  s.  c  om*/
    Rectangle2D bounds = mLayout.getBounds();
    Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight());
    g2.fill(back);

    g2.setPaint(Color.white);
    g2.setFont(mFont);
    g2.drawString(s, (float) x, (float) -bounds.getY());
    return advance;
}

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

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

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xBBBBDD));

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();

    // 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);
    renderer.setMaximumBarWidth(0.10);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    // OPTIONAL CUSTOMISATION COMPLETED.
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    setCategorySummary(dataset);
    return chart;

}

From source file:com.twocents.report.charts.BarChartDemo1.java

/**
 * Creates a sample chart.//ww  w .  j  a va 2s. c om
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("Bar 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?
    );

    // 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:lab10part2.Chart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from  w ww. j  a  v a 2 s. com

    // 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:savant.view.swing.Frame.java

/**
 * Construct a new Frame for holding a track.
 *
 * @param df the DataFormat, so the frame can do any format-specific
 * initialisation (e.g. smaller height for sequence tracks)
 *//*from w ww  . j av a  2  s .co  m*/
public Frame(DataFormat df) {
    super(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK));
    sequence = df == DataFormat.SEQUENCE;

    // Component which displays the legend component.
    legend = new JComponent() {
        @Override
        public Dimension getPreferredSize() {
            for (Track t : tracks) {
                Dimension d = t.getRenderer().getLegendSize(t.getDrawingMode());
                if (d != null) {
                    return d;
                }
            }
            return new Dimension(0, 0);
        }

        @Override
        public Dimension getMinimumSize() {
            return getPreferredSize();
        }

        @Override
        public void paintComponent(Graphics g) {
            for (Track t : tracks) {
                Dimension d = t.getRenderer().getLegendSize(t.getDrawingMode());
                if (d != null) {
                    Graphics2D g2 = (Graphics2D) g;
                    GradientPaint gp = new GradientPaint(0, 0, Color.WHITE, 0, 60, new Color(230, 230, 230));
                    g2.setPaint(gp);
                    g2.fillRect(0, 0, d.width, d.height);

                    g2.setColor(Color.BLACK);
                    g2.draw(new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1));
                    t.getRenderer().drawLegend(g2, t.getDrawingMode());
                    return;
                }
            }
        }
    };
    legend.setVisible(false);

    frameLandscape = new JLayeredPane();

    //add graphPane -> jlp -> scrollPane
    jlp = new JLayeredPane();
    jlp.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.gridx = 0;
    gbc.gridy = 0;

    //scrollpane
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setWheelScrollingEnabled(false);
    scrollPane.setBorder(null);

    graphPane = new GraphPane(this);
    jlp.add(graphPane, gbc, 0);

    scrollPane.getViewport().add(jlp);

    //GRID FRAMEWORK AND COMPONENT ADDING...
    frameLandscape.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;

    //add sidepanel
    sidePanel = new JPanel() {
        @Override
        public Dimension getMinimumSize() {
            return new Dimension(0, 0);
        }
    };
    sidePanel.setLayout(new GridBagLayout());
    sidePanel.setOpaque(false);
    sidePanel.setVisible(false);
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 1;
    c.gridy = 0;
    c.insets = new Insets(0, 0, 0, 16); // Leave 16 pixels so that we don't sit on top of the scroll-bar.
    frameLandscape.setLayer(sidePanel, JLayeredPane.PALETTE_LAYER);
    frameLandscape.add(sidePanel, c);

    addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            Dimension dim = getSize();
            if (dim != null) {
                // TODO: The following shouldn't be necessary, but it seems to be.
                int expectedWidth = frameLandscape.getWidth();
                if (expectedWidth != graphPane.getWidth()) {
                    Dimension goodSize = new Dimension(expectedWidth, graphPane.getHeight());
                    graphPane.setPreferredSize(goodSize);
                    graphPane.setSize(goodSize);
                }

                setLegendVisible(true);
            }
        }
    });

    //add graphPane to all cells
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 2;
    c.gridheight = 1;
    c.insets = new Insets(0, 0, 0, 0);

    frameLandscape.setLayer(scrollPane, JLayeredPane.DEFAULT_LAYER);
    frameLandscape.add(scrollPane, c);

    // Add our progress-panel.  If setTracks is called promptly, it will be cleared
    // away before it ever has a chance to draw.
    getContentPane().add(new ProgressPanel(null), BorderLayout.CENTER);
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

/**<!====== drawItem ======================================================>
   Draws a 3D bar to represent one data item.
   <!      Name       Description>
   @param  g2         the graphics device.
   @param  state      the renderer state.
   @param  dataArea   the area for plotting the data.
   @param  plot       the plot.// w w w.j av a 2s  . com
   @param  domainAxis the domain axis.
   @param  rangeAxis  the range axis.
   @param  dataset    the dataset.
   @param  row        the row index (zero-based).
   @param  column     the column index (zero-based).
   @param  pass       the pass index.
<!=======================================================================>*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    g2.setStroke(new BasicStroke(1));
    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color endColor = getFrontDark((Color) itemPaint);
        Color startColor = (Color) itemPaint;
        Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor,
                (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor);
        g2.setPaint(paint);
    }
    g2.fill(bar);

    double x0 = bar.getMinX(); // left
    double x1 = x0 + getXOffset(); // offset left
    double x2 = bar.getMaxX(); // right
    double x3 = x2 + getXOffset(); // offset right

    double y0 = bar.getMinY() - getYOffset(); // offset top
    double y1 = bar.getMinY(); // bar top
    double y2 = bar.getMaxY() - getYOffset(); // offset bottom
    double y3 = bar.getMaxY(); // bottom

    //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight());

    Line2D.Double line = new Line2D.Double(x2, y1, x2, y3);
    g2.draw(line);

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    g2.setPaint(itemPaint);

    // Draw the right side
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            Color startColor = getSideLight((Color) itemPaint);
            Color endColor = getSideDark((Color) itemPaint);
            Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3,
                    endColor);
            g2.setPaint(paint);
        }
        g2.fill(bar3dRight);
    }

    // Draw the top
    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1); // bottom left
    bar3dTop.lineTo((float) x1, (float) y0); // top left
    bar3dTop.lineTo((float) x3, (float) y0); // top right
    bar3dTop.lineTo((float) x2, (float) y1); // bottom right
    bar3dTop.closePath();
    if (itemPaint instanceof Color) {
        Color endColor = getTopDark((Color) itemPaint);
        Color startColor = getTopLight((Color) itemPaint);
        //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor);
        Point2D.Double topRight = new Point2D.Double(x3, y0);
        Point2D.Double bottomLeft = new Point2D.Double(x0, y1);
        //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2)));
        Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2)));
        Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor,
                (float) darkEnd.getX(), (float) darkEnd.getY(), endColor);
        g2.setPaint(paint);
        //drawMarker(topRight, g2, startColor);
    }
    g2.fill(bar3dTop);
    g2.setPaint(itemPaint);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }

}

From source file:com.polivoto.vistas.acciones.Datos.java

private JFreeChart crearChartPie(PieDataset dataset, String titulo) {
    JFreeChart chart = ChartFactory.createPieChart(titulo, dataset, false, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(290);/*from w ww.j  a  va2s  .com*/
    plot.setDirection(Rotation.ANTICLOCKWISE);

    plot.setNoDataMessage("No hay votos");
    try {
        if (ac.getConteoOpcionesPregunta().getJSONObject(pox).getInt("participantes") != 0) {
            int j = 0;
            for (int i = 0; i < ac.getConteoOpcionesPregunta().getJSONObject(pox).getJSONArray("conteo")
                    .length(); i++) {
                try {
                    if (ac.getConteoOpcionesPregunta().getJSONObject(pox).getJSONArray("conteo")
                            .getJSONObject(i).getString("reactivo").equals("Anular mi voto")) {
                        plot.setSectionPaint("Nulo", Color.lightGray);
                    } else {
                        plot.setSectionPaint(ac.getConteoOpcionesPregunta().getJSONObject(pox)
                                .getJSONArray("conteo").getJSONObject(i).getString("reactivo"), colores.get(j));
                        j++;
                    }
                } catch (JSONException ex) {
                    ex.printStackTrace();
                }
            }
        }
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    plot.setSimpleLabels(true);
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {2} de votos",
            new DecimalFormat("0"), new DecimalFormat("0.000%"));
    plot.setLabelGenerator(gen);
    if (rotating) {
        final Rotator rotate = new Rotator(plot);
        rotate.start();
    }
    return chart;
}

From source file:com.bdb.weather.display.current.WindGauge.java

/**
 * Constructor./*  ww w. j  ava2 s.  c om*/
 */
public WindGauge() {
    this.setPrefSize(200.0, 200.0);
    lastHeading = 0.0;
    lastSpeed = 0.0;
    plot = new DialPlot();
    for (int i = 0; i < WIND_DIR_ITEMS; i++) {
        datasets[i] = new DefaultValueDataset();
        plot.setDataset(WIND_DIR_DATASET_INDEX_BASE + i, datasets[i]);
    }

    plot.setDataset(WIND_SPEED_DATASET_INDEX, speedDataset);
    plot.setDataset(WIND_GUST_DATASET_INDEX, gustDataset);
    plot.setDataset(MAX_WIND_SPEED_DATASET_INDEX, maxSpeedDataset);
    plot.setDataset(MAX_WIND_GUST_DATASET_INDEX, maxGustDataset);

    plot.addLayer(
            new DialBackground(new GradientPaint(0.0f, 0.0f, Color.LIGHT_GRAY, 100.0f, 0.0f, Color.blue)));

    StandardDialScale scale = new StandardDialScale(0.0, 360.0, 90.0, -360.0, 45.0, 1);
    scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN));
    scale.setTickRadius(.9);
    scale.setTickLabelFormatter(new CompassHeadingFormat());
    scale.setTickLabelOffset(0.06);
    scale.setMajorTickPaint(new Color(0, 0, 0, 0));
    scale.setTickLabelPaint(Color.BLACK);
    scale.setMinorTickLength(scale.getMajorTickLength());
    scale.setMinorTickStroke(scale.getMajorTickStroke());
    plot.addScale(WIND_DIR_SCALE, scale);

    scale = new StandardDialScale(0.0, 50.0, 225.0, -270.0, 10.0, 9);
    scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN));
    scale.setTickRadius(.4);
    scale.setTickLabelFormatter(new DecimalFormat("##"));
    scale.setTickLabelOffset(.15);
    scale.setTickLabelPaint(Color.BLACK);
    plot.addScale(WIND_SPEED_SCALE, scale);

    DialPointer.Pointer pointer;
    for (int i = 1; i < WIND_DIR_ITEMS; i++) {
        pointer = new WindDirPointer(.72, .2, WIND_DIR_DATASET_INDEX_BASE + i, false);
        pointer.setOutlinePaint(Color.RED);
        plot.addPointer(pointer);
    }

    plot.setDialFrame(new StandardDialFrame());
    pointer = new WindDirPointer(.72, .2, WIND_DIR_DATASET_INDEX_BASE, true);
    Color fill = Color.CYAN;
    pointer.setFillPaint(fill);
    pointer.setOutlinePaint(Color.BLACK);
    plot.addPointer(pointer);

    DialCap cap = new DialCap();
    plot.setCap(cap);

    DialPointer.Pin speedPin = new DialPointer.Pin(WIND_SPEED_DATASET_INDEX);
    speedPin.setPaint(WIND_SPEED_PIN_COLOR);
    speedPin.setRadius(WIND_SPEED_PIN_RADIUS);
    speedPin.setStroke(new BasicStroke(WIND_SPEED_PIN_WIDTH, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    plot.addPointer(speedPin);

    DialPointer.Pin gustPin = new DialPointer.Pin(WIND_GUST_DATASET_INDEX);
    gustPin.setPaint(WIND_GUST_PIN_COLOR);
    gustPin.setRadius(WIND_GUST_PIN_RADIUS);
    gustPin.setStroke(new BasicStroke(WIND_SPEED_PIN_WIDTH, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    plot.addPointer(gustPin);

    DialPointer.Pin maxSpeedPin = new DialPointer.Pin(MAX_WIND_SPEED_DATASET_INDEX);
    maxSpeedPin.setPaint(WIND_SPEED_PIN_COLOR);
    maxSpeedPin.setRadius(MAX_WIND_SPEED_PIN_RADIUS);
    maxSpeedPin
            .setStroke(new BasicStroke(MAX_WIND_SPEED_PIN_WIDTH, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    plot.addPointer(maxSpeedPin);

    DialPointer.Pin maxGustPin = new DialPointer.Pin(MAX_WIND_GUST_DATASET_INDEX);
    maxGustPin.setPaint(WIND_GUST_PIN_COLOR);
    maxGustPin.setRadius(MAX_WIND_GUST_PIN_RADIUS);
    maxGustPin
            .setStroke(new BasicStroke(MAX_WIND_SPEED_PIN_WIDTH, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    plot.addPointer(maxGustPin);

    speedAnnotation.setAngle(270.0);
    speedAnnotation.setRadius(.35);
    speedAnnotation.setPaint(Color.cyan);
    plot.addLayer(speedAnnotation);

    double angle = speedAnnotation.getAngle();
    double radius = speedAnnotation.getRadius();

    avgAnnotation.setPaint(Color.cyan);
    avgAnnotation.setAngle(angle);
    avgAnnotation.setRadius(radius + .1);
    plot.addLayer(avgAnnotation);

    for (int i = 0; i < WIND_DIR_ITEMS; i++)
        plot.mapDatasetToScale(WIND_DIR_DATASET_INDEX_BASE + i, WIND_DIR_SCALE);

    plot.mapDatasetToScale(WIND_SPEED_DATASET_INDEX, WIND_SPEED_SCALE);
    plot.mapDatasetToScale(WIND_GUST_DATASET_INDEX, WIND_SPEED_SCALE);
    plot.mapDatasetToScale(MAX_WIND_SPEED_DATASET_INDEX, WIND_SPEED_SCALE);
    plot.mapDatasetToScale(MAX_WIND_GUST_DATASET_INDEX, WIND_SPEED_SCALE);

    StandardDialRange range = new StandardDialRange(0.0, 360.0, Color.BLACK);
    range.setInnerRadius(.70);
    range.setOuterRadius(.72);
    range.setScaleIndex(WIND_DIR_SCALE);
    plot.addLayer(range);

    JFreeChart chart = new JFreeChart(plot);
    chart.setBackgroundPaint(Color.GRAY);

    chartViewer = new ChartViewer(chart);
    //chartViewer.setMinHeight(100);
    //chartViewer.setMinWidth(100);
    //chartViewer.setMaxHeight(400);
    //chartViewer.setMaxWidth(400);
    //chartViewer.setBackground(Color.GRAY);
    //chartViewer.setBorder(new BevelBorder(BevelBorder.RAISED));

    this.setCenter(chartViewer);
    this.setTop(title);
    BorderPane.setAlignment(title, Pos.CENTER);
    title.textProperty().bind(titleProperty);
    setTitle("Wind");

    timeline.setCycleCount(9);
    timeline.setOnFinished((event) -> {
        datasets[0].setValue(currentHeading);
        speedDataset.setValue(currentSpeed);
        lastHeading = currentHeading;
        lastSpeed = currentSpeed;
    });
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java

private static JFreeChart createChart(BarGraphDataSeries dataSeries) {
    if (dataSeries == null)
        return null;

    BarGraphDataSeries ds = dataSeries;//  w  w w  .j a  v a  2 s . c  o m

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(ds.getTitle(), // chart title
            ds.getDomainLabel(), // domain axis label
            ds.getRangeLabel(), // range axis label
            ds.getDataSet(0), // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainGridlinesVisible(true);

    // 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));
    GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

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

    ValueRange vr = ds.getRangeValueRanges().get(0);
    if (vr != null) {
        Range range = new Range(vr.getMin() / vr.getScale(), vr.getMax() / vr.getScale());
        rangeAxis.setRange(range);
    }
    return chart;

}

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

/**
 * Returns an array of paint objects that will be used for the bar colors.
 * /*from   w  ww  .ja v  a 2 s  .  c  om*/
 * @return An array of paint objects.
 */
private static Paint[] createPaint() {
    Paint[] colors = new Paint[5];
    colors[0] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.red);
    colors[1] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.green);
    colors[2] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.blue);
    colors[3] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.orange);
    colors[4] = new GradientPaint(0f, 0f, Color.white, 0f, 0f, Color.magenta);
    return colors;
}