Example usage for java.awt BasicStroke CAP_ROUND

List of usage examples for java.awt BasicStroke CAP_ROUND

Introduction

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

Prototype

int CAP_ROUND

To view the source code for java.awt BasicStroke CAP_ROUND.

Click Source Link

Document

Ends unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen.

Usage

From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java

private JFreeChart createChart(XYDataset dataset, boolean createLegend) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, createLegend, // include legend
            true, // tooltips
            false // urls
    );//w  ww  .java 2s.  c  o m

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    DeviationRenderer renderer = new DeviationRenderer(true, false);

    // colors
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else { // special case needed for avoiding devision by zero
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            renderer.setSeriesPaint(i,
                    getColorProvider().getPointColor(1.0d - i / (double) (dataset.getSeriesCount() - 1)));
        }
    }
    // background for bounds
    if (plotBounds) {
        float[] dashArray = new float[] { 7, 14 };
        renderer.setSeriesStroke(boundsSeriesIndex,
                new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dashArray, 0));
        renderer.setSeriesPaint(boundsSeriesIndex, Color.GRAY.brighter());
        renderer.setSeriesFillPaint(boundsSeriesIndex, Color.GRAY);
    }
    // alpha
    renderer.setAlpha(0.25f);

    plot.setRenderer(renderer);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    if (axis[INDEX] < 0) {
        xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        xAxis.setLabel(SERIESINDEX_LABEL);
        Range range = getRangeForName(SERIESINDEX_LABEL);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    } else {
        xAxis.setLabel(dataTable.getColumnName(axis[INDEX]));
        Range range = getRangeForDimension(axis[INDEX]);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    }

    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel(VALUEAXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
    setYAxisRange(yAxis);

    yAxis.setLabelFont(LABEL_FONT_BOLD);
    yAxis.setTickLabelFont(LABEL_FONT);

    return chart;
}

From source file:grafici.StatisticheLineChart.java

/**
 * Creates a sample chart.//from  w w w .j  av a  2  s .  co  m
 * 
 * @param dataset
 *            the dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset, Table results, int variabile, int valore) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart(titolo, "", // domain axis label
            results.getColumn(valore).getText().toUpperCase(), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

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

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //           renderer.setDrawShapes(true);

    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 2.0f, 6.0f }, 0.0f));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:scrum.server.common.BurndownChart.java

private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay,
        Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit,
        float widthPerDay) {
    DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay,
            freeDays);//  w  w w  . j  a va2 s . c  om

    double tick = 1.0;
    double max = BurndownChart.getMaximum(data);

    while (max / tick > 25) {
        tick *= 2;
        if (max / tick <= 25)
            break;
        tick *= 2.5;
        if (max / tick <= 25)
            break;
        tick *= 2;
    }
    double valueLabelTickUnit = tick;
    double upperBoundary = Math.min(max * 1.1f, max + 3);

    if (!Sys.isHeadless())
        LOG.warn("GraphicsEnvironment is not headless");
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true,
            false);

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = chart.getXYPlot();
    // plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    // plot.setOutlineVisible(false);

    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.lightGray);
    // plot.setRangeCrosshairPaint(Color.lightGray);
    // plot.setRangeMinorGridlinePaint(Color.lightGray);
    // plot.setDomainCrosshairPaint(Color.blue);
    // plot.setDomainMinorGridlinePaint(Color.green);
    // plot.setDomainTickBandPaint(Color.green);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2f));

    renderer.setSeriesPaint(0, COLOR_PAST_LINE);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE);
    renderer.setSeriesStroke(1,
            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0));
    renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE);
    renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    DateAxis domainAxis1 = new DateAxis();
    String dateFormat = "d.";
    widthPerDay -= 5;
    if (widthPerDay > 40) {
        dateFormat = "EE " + dateFormat;
    }
    if (widthPerDay > 10) {
        float spaces = widthPerDay / 2.7f;
        dateFormat = Str.multiply(" ", (int) spaces) + dateFormat;
    }
    domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US));
    domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit));
    domainAxis1.setAxisLineVisible(false);
    Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis());
    domainAxis1.setRange(range);

    DateAxis domainAxis2 = new DateAxis();
    domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
    domainAxis2.setTickMarksVisible(false);
    domainAxis2.setTickLabelsVisible(false);
    domainAxis2.setRange(range);

    plot.setDomainAxis(0, domainAxis2);
    plot.setDomainAxis(1, domainAxis1);
    plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit));

    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(upperBoundary);

    plot.setRangeAxis(rangeAxis);

    return chart;
}

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

/**
 * Creates a sample chart./*from   w  ww .  jav  a 2 s.c  o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 5", // chart title
            "Type", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    final Shape[] shapes = new Shape[3];
    int[] xpoints;
    int[] ypoints;

    // right-pointing triangle
    xpoints = new int[] { -3, 3, -3 };
    ypoints = new int[] { -3, 0, 3 };
    shapes[0] = new Polygon(xpoints, ypoints, 3);

    // vertical rectangle
    shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

    // left-pointing triangle
    xpoints = new int[] { -3, 3, 3 };
    ypoints = new int[] { 0, -3, 3 };
    shapes[2] = new Polygon(xpoints, ypoints, 3);

    final DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setDrawingSupplier(supplier);

    chart.setBackgroundPaint(Color.yellow);

    // set the stroke for each series...
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 6.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 2.0f, 6.0f }, 0.0f));

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);
    renderer.setItemLabelsVisible(true);
    //      renderer.setLabelGenerator(new StandardCategoryLabelGenerator());

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

    return chart;

}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

/**
 * Render the pie chart with the given height
 * //from  w  ww .ja va  2  s .co  m
 * @param height
 *          The height of the resulting image
 * @return The pie chart rendered as an image
 */
public BufferedImage render(int height) {
    BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.scale(zoom, zoom);
    // fill background to white
    g2.setColor(Color.WHITE);
    g2.fill(new Rectangle(totalWidth, totalHeight));
    // prepare render hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    // draw shadow image
    g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver());

    double start = 0;
    List<Arc2D> pies = new ArrayList<>();
    // pie segmente erzeugen und fuellen
    if (total == 0) {
        g2.setColor(BRIGHT_GRAY);
        g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
        g2.setColor(Color.WHITE);
        g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
    } else {
        for (Segment s : segments) {
            double portionDegrees = s.getPortion() / total;
            Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor());
            if (withSubSegments) {
                double smallRadius = radius * s.getSubSegmentRatio();
                paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker());
            }
            start += portionDegrees;
            // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen)
            String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0);
            p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25")
            s.setPercent(p + "%");
            pies.add(pie);
        }
        // weissen Rahmen um die pie segmente zeichen
        g2.setColor(Color.WHITE);
        for (Arc2D pie : pies) {
            g2.draw(pie);
        }
    }
    // Legende zeichnen
    renderLegend(g2);
    // "xx%" Label direkt auf die pie segmente zeichen
    g2.setColor(Color.WHITE);
    float fontSize = 32f;
    g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD));
    start = 0;
    for (Segment s : segments) {
        if (s.getPortion() < 1E-6) {
            continue; // ignore segments with portions that are extremely small
        }
        double portionDegrees = s.getPortion() / total;
        double angle = start + portionDegrees / 2; // genau in der Mitte des Segments
        double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char
        int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt);
        int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2);
        g2.drawString(s.getPercent(), x, y);
        start += portionDegrees;
    }
    return image;
}

From source file:edu.scripps.fl.curves.plot.CurvePlot.java

public void addLineAt(double response) {
    addLineAt(response, Color.LIGHT_GRAY, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
}

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

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

    JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    Shape[] shapes = new Shape[3];
    int[] xpoints;
    int[] ypoints;

    // right-pointing triangle
    xpoints = new int[] { -3, 3, -3 };
    ypoints = new int[] { -3, 0, 3 };
    shapes[0] = new Polygon(xpoints, ypoints, 3);

    // vertical rectangle
    shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6);

    // left-pointing triangle
    xpoints = new int[] { -3, 3, 3 };
    ypoints = new int[] { 0, -3, 3 };
    shapes[2] = new Polygon(xpoints, ypoints, 3);

    DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDrawingSupplier(supplier);

    // set the stroke for each series...
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 6.0f, 6.0f }, 0.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
            1.0f, new float[] { 2.0f, 6.0f }, 0.0f));

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

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

    setCategorySummary(dataset);
    return chart;

}

From source file:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java

private JFreeChart createChart() {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );//from  ww  w . j  a  va2  s.c o m

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
        if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            chart.getXYPlot().setDomainAxis(domainAxis);
        }
    } else {
        plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) {
        xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    } else {
        xAxis.setLabel(SERIESINDEX_LABEL);
    }
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
        if (getRangeForDimension(indexAxis) != null) {
            xAxis.setRange(getRangeForDimension(indexAxis));
        }
    } else {
        if (getRangeForName(SERIESINDEX_LABEL) != null) {
            xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
        }
    }

    // renderer and range axis
    synchronized (dataTable) {
        int numberOfSelectedColumns = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    numberOfSelectedColumns++;
                }
            }
        }

        int columnCount = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    // YIntervalSeries series = new
                    // YIntervalSeries(this.dataTable.getColumnName(c));
                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries(dataTable.getColumnName(c));
                    Iterator<DataTableRow> i = dataTable.iterator();
                    int index = 1;
                    while (i.hasNext()) {
                        DataTableRow row = i.next();
                        double value = row.getValue(c);

                        if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                            double indexValue = row.getValue(indexAxis);
                            series.add(indexValue, value);
                        } else {
                            series.add(index++, value);
                        }
                    }
                    dataset.addSeries(series);

                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

                    Color color = getColorProvider().getPointColor(1.0d);
                    if (numberOfSelectedColumns > 1) {
                        color = getColorProvider()
                                .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
                    }
                    renderer.setSeriesPaint(0, color);
                    renderer.setSeriesStroke(0,
                            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                    renderer.setSeriesShapesVisible(0, false);

                    NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
                    if (getRangeForDimension(c) != null) {
                        yAxis.setRange(getRangeForDimension(c));
                    } else {
                        yAxis.setAutoRange(true);
                        yAxis.setAutoRangeStickyZero(false);
                        yAxis.setAutoRangeIncludesZero(false);
                    }
                    yAxis.setLabelFont(LABEL_FONT_BOLD);
                    yAxis.setTickLabelFont(LABEL_FONT);
                    if (numberOfSelectedColumns > 1) {
                        yAxis.setAxisLinePaint(color);
                        yAxis.setTickMarkPaint(color);
                        yAxis.setLabelPaint(color);
                        yAxis.setTickLabelPaint(color);
                    }

                    plot.setRangeAxis(columnCount, yAxis);
                    plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

                    plot.setDataset(columnCount, dataset);
                    plot.setRenderer(columnCount, renderer);
                    plot.mapDatasetToRangeAxis(columnCount, columnCount);

                    columnCount++;
                }
            }
        }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
}

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

/**
 * Creates a sample chart./*from w w w.jav  a2s.c  om*/
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title
            "Type", // 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...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    //    legend.setShapeScaleX(1.5);
    //  legend.setShapeScaleY(1.5);
    //legend.setDisplaySeriesLines(true);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

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

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // customise the renderer...
    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    //        renderer.setDrawShapes(true);

    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 2.0f, 6.0f }, 0.0f));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:edu.cudenver.bios.chartsvc.resource.ScatterPlotResource.java

/**
 * Create a JFreeChart object from the chart specification.  JFreechart provides 
 * functionality to render 2D scatter plots as jpeg images
 * /*from w w  w  . j a v  a2 s.  com*/
 * @param chart chart specification object
 * @return JFreeChart object
 * @throws ResourceException
 */
private JFreeChart buildScatterPlot(Chart chart) throws ResourceException {
    ArrayList<LineStyle> lineStyleList = chart.getLineStyleList();

    float dashedLength = 1.0f;
    float spaceLength = 1.0f;
    float thickness = 1.0f;

    // the first series is treated as the x values
    if (chart.getSeries() == null || chart.getSeries().size() <= 0)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified");

    // create the jfree chart series
    XYSeriesCollection chartData = new XYSeriesCollection();
    // use a spline renderer to make the connecting lines smooth
    XYSplineRenderer rend = new XYSplineRenderer();

    int seriesIdx = 0;

    for (Series series : chart.getSeries()) {
        XYSeries xySeries = new XYSeries(series.getLabel());

        List<Double> xList = series.getXCoordinates();
        List<Double> yList = series.getYCoordinates();
        if (xList != null && yList != null && xList.size() == yList.size()) {
            for (int i = 0; i < xList.size(); i++) {
                xySeries.add(xList.get(i), yList.get(i));
            }
        }

        if (seriesIdx >= 0 && seriesIdx < lineStyleList.size()) {
            LineStyle lineStyle = lineStyleList.get(seriesIdx);
            dashedLength = (float) lineStyle.getDashLength();
            spaceLength = (float) lineStyle.getSpaceLength();
            thickness = (float) lineStyle.getWidth();
        } else {
            dashedLength = 1.0f;
            spaceLength = 1.0f;
            thickness = 1.0f;
        }

        // set the line style
        rend.setSeriesPaint(seriesIdx, Color.BLACK);

        if (seriesIdx >= 0) {
            /*rend.setSeriesStroke(seriesIdx, 
                  new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {(float) seriesIdx, (float) 2*seriesIdx}, 0.0f));*/
            rend.setSeriesStroke(seriesIdx, new BasicStroke(thickness, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND, 1.0f, new float[] { dashedLength, spaceLength }, 0.0f));
        }
        // add the series to the data set
        chartData.addSeries(xySeries);
        seriesIdx++;
    }

    // turn off shapes displayed at each data point to make a smooth curve
    rend.setBaseShapesVisible(false);

    // Create the line chart
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    if (chart.getXAxis() != null) {
        Axis xAxisSpec = chart.getXAxis();
        xAxis.setLabel(xAxisSpec.getLabel());
        if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) {
            xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax());
        }
    }
    NumberAxis yAxis = new NumberAxis();
    if (chart.getYAxis() != null) {
        Axis yAxisSpec = chart.getYAxis();
        yAxis.setLabel(chart.getYAxis().getLabel());
        if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) {
            xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax());
        }
    }
    XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    JFreeChart renderedChart = new JFreeChart(chart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    renderedChart.setBackgroundPaint(Color.WHITE);
    if (chart.hasLegend()) {
        LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
        legend.setFrame(BlockBorder.NONE);
        legend.setPosition(RectangleEdge.BOTTOM);
        renderedChart.addLegend(legend);
    }

    return renderedChart;
}