Example usage for java.awt BasicStroke CAP_SQUARE

List of usage examples for java.awt BasicStroke CAP_SQUARE

Introduction

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

Prototype

int CAP_SQUARE

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

Click Source Link

Document

Ends unclosed subpaths and dash segments with a square projection that extends beyond the end of the segment to a distance equal to half of the line width.

Usage

From source file:org.jstockchart.plot.TimeseriesPlot.java

private CombinedDomainXYPlot createCombinedXYPlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    LogicDateAxis logicDateAxis = timeseriesArea.getlogicDateAxis();
    TimeseriesDateAxis dateAxis = new TimeseriesDateAxis(logicDateAxis.getLogicTicks());
    if (timeline != null) {
        dateAxis.setTimeline(timeline);//from w w  w.  j  ava 2s  . c om
    }
    dateAxis.setTickLabelFont(axisFont);
    dateAxis.setTickMarkStroke(stroke);
    List<String> hideTick = new ArrayList<String>();
    hideTick.add("10:00");
    hideTick.add("11:00");
    hideTick.add("13:30");
    //hideTick.add("14:30");
    hideTick.add("14:30");
    dateAxis.setHideTickLabel(hideTick);
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    dateAxis.setTickMarksVisible(false);
    Date startTime = DateUtils.createDate(2008, 1, 1, 9, 30, 0);
    Date endTime = DateUtils.createDate(2008, 1, 1, 15, 0, 0);
    dateAxis.setRange(timeseriesArea.getStartDate(), timeseriesArea.getEndDate());
    dateAxis.setAxisLineVisible(false);
    CFXCombinedPlot combinedDomainXYPlot = new CFXCombinedPlot(dateAxis);
    combinedDomainXYPlot.setInsets(new RectangleInsets(5, 2, 4, 2));

    AxisSpace axisSpace = new AxisSpace();
    axisSpace.setBottom(22);
    axisSpace.setLeft(0);
    axisSpace.setRight(0);
    axisSpace.setTop(0);
    combinedDomainXYPlot.setFixedDomainAxisSpace(axisSpace);
    combinedDomainXYPlot.setGap(0);
    combinedDomainXYPlot.setOrientation(timeseriesArea.getOrientation());
    combinedDomainXYPlot.setDomainAxis(dateAxis);
    combinedDomainXYPlot.setDomainAxisLocation(timeseriesArea.getDateAxisLocation());

    if (timeseriesArea.getPriceWeight() <= 0 && timeseriesArea.getVolumeWeight() <= 0) {
        throw new IllegalArgumentException("Illegal weight value: priceWeight="
                + timeseriesArea.getPriceWeight() + ", volumeWeight=" + timeseriesArea.getVolumeWeight());
    }

    if (timeseriesArea.getPriceWeight() > 0) {
        XYPlot pricePlot = createPricePlot();
        combinedDomainXYPlot.add(pricePlot, timeseriesArea.getPriceWeight());
    }

    if (timeseriesArea.getVolumeWeight() > 0) {
        XYPlot volumePlot = createVolumePlot();
        combinedDomainXYPlot.add(volumePlot, timeseriesArea.getVolumeWeight());
    }

    return combinedDomainXYPlot;
}

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

public void setLineWidth(double width) {
    this.strokeSequence = new Stroke[] {
            new BasicStroke((float) width, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL) };
}

From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java

/**
 * This method should be called after a chart dataset is updated. It
 * will iterate over all XYDatasets and provide the line color and lineStyle.
 * If it is called before a chart has a dataset, it will not have an effect.
 *
 * @param plot/*from w w w. j  av  a2s  . co  m*/
 */
public void setXYPlotRenderer(XYPlot plot) {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    int n = plot.getSeriesCount();

    for (int i = 0; i < n; i++) {
        Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                getLineStyle(i), 0.0f);
        renderer.setSeriesStroke(i, stroke);
        renderer.setSeriesPaint(i, getPaintColor(i));
    }
    renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5));
    renderer.setBaseShapesFilled(false);
    renderer.setBaseShapesVisible(showMarkers);
    renderer.setDrawSeriesLineAsPath(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRenderer(renderer);
}

From source file:peakml.util.jfreechart.FastErrorBarPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//from ww w. j a va 2 s.c  o  m
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // create the strokes
    BasicStroke stroke_solid = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f);
    BasicStroke stroke_dashed = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f,
            new float[] { 2, 4 }, 0);

    g2.setStroke(stroke_solid);

    // count the number of labels
    int categoryCount = 0;
    if (showall) {
        for (Data data : dataseries)
            categoryCount += data.yvalues.length;
    } else
        categoryCount = dataseries.size();

    // draw all the values
    int pos = 0;
    boolean dashed = false;
    double prevx = -1, prevy = -1;
    for (Data data : dataseries) {
        if (data.yvalues.length == 0) {
            dashed = true;
            pos++;
            continue;
        }

        double mean[] = showall ? data.yvalues : new double[] { data.getMeanY() };
        double min[] = showall ? data.yvalues : new double[] { data.getMinY() };
        double max[] = showall ? data.yvalues : new double[] { data.getMaxY() };
        for (int i = 0; i < mean.length; ++i) {
            double ypos, xpos = xaxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, pos++, categoryCount,
                    dataArea, RectangleEdge.BOTTOM);

            // draw the mean value
            g2.setColor(Color.RED);
            ypos = yaxis.valueToJava2D(mean[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos, (int) xpos + 2, (int) ypos);

            // conect the dots
            if (prevx != -1 && prevy != -1) {
                g2.setColor(Color.BLACK);
                if (dashed)
                    g2.setStroke(stroke_dashed);
                g2.drawLine((int) prevx, (int) prevy, (int) xpos, (int) ypos);
                if (dashed) {
                    dashed = false;
                    g2.setStroke(stroke_solid);
                }

            }
            prevy = ypos;
            prevx = xpos;

            // draw the outer values
            g2.setColor(Color.LIGHT_GRAY);
            double ypos_min = yaxis.valueToJava2D(min[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_min, (int) xpos + 2, (int) ypos_min);
            double ypos_max = yaxis.valueToJava2D(max[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_max, (int) xpos + 2, (int) ypos_max);
            g2.drawLine((int) xpos, (int) ypos_min, (int) xpos, (int) ypos_max);
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java

public void setXYPlotRendererWithPoints(XYPlot plot) {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    int n = plot.getSeriesCount();
    int half = (int) (n / 2.0);

    //assume first half are series for lines and second half are series for points

    for (int i = 0; i < n; i++) {
        if (i < half) {
            //Add lines
            Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                    getLineStyle(i), 0.0f);
            renderer.setSeriesStroke(i, stroke);
            renderer.setSeriesPaint(i, getPaintColor(i));
            renderer.setSeriesShapesFilled(i, false);
            renderer.setSeriesShapesVisible(i, showMarkers);
            renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5));
            renderer.setDrawSeriesLineAsPath(true);

        } else {/*  ww  w . ja  va 2 s . c o m*/
            //Add points
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesFilled(i, false);
            renderer.setSeriesShapesVisible(i, true);
            renderer.setSeriesPaint(i, getPaintColor(i - half));
        }
    }

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRenderer(renderer);
}

From source file:org.squale.squaleweb.util.graph.KiviatMaker.java

/**
 * Create the JreeChart object//from  w  w  w . ja  v a  2  s.co  m
 * 
 * @param showLegend indicate if it should display the legend or not
 * @param showBackground indicate if we want showBackground
 * @return The JreeChart object
 */
public JFreeChart getChart(boolean showLegend, boolean showBackground) {
    JFreeChart retChart = super.getChart();

    // Creation of the graph if it not already exist
    if (null == retChart) {

        // Creation of the plot
        SpiderWebPlot plot = new SpiderWebPlot(mDataset);

        // Creation of the picture. The plot is inside the picture
        retChart = new JFreeChart(mTitle, TextTitle.DEFAULT_FONT, plot, false);

        // Display of the legend
        if (showLegend) {
            LegendTitle legendtitle = new LegendTitle(plot);
            legendtitle.setPosition(RectangleEdge.BOTTOM);
            retChart.addSubtitle(legendtitle);
        }

        // Definition of the style of the three first draw in the spiderWEbPlot.
        // This three first draw represent the scale for the mark 1.0, 2.0 and 3.0 in the plot
        // First we define the style
        final float miterLimit = 10.0f;
        final float[] dashPattern = { 5.0f, 3.0f };
        BasicStroke dash = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, // End cap
                BasicStroke.JOIN_MITER, // Join style
                miterLimit, // Miter limit
                dashPattern, // Dash pattern
                0.0f);
        // We associate this style to the draw
        plot.setSeriesPaint(0, new Color(WebMessages.getInt("kiviat.color.1")));
        plot.setSeriesOutlineStroke(0, dash);
        plot.setSeriesPaint(1, new Color(WebMessages.getInt("kiviat.color.2")));
        plot.setSeriesOutlineStroke(1, dash);
        plot.setSeriesPaint(2, new Color(WebMessages.getInt("kiviat.color.3")));
        plot.setSeriesOutlineStroke(2, dash);

        // Define the gap what is draw and the border of the plot
        plot.setInteriorGap(DEFAULT_GAP);

        // Define the style of the line stroke
        plot.setBaseSeriesOutlineStroke(new BasicStroke(2.0f));

        // The max value put in the plot (for the scale)
        plot.setMaxValue(SCALE_MAX_VALUE);

        // Indicate if we want fill the inner of the draw
        plot.setWebFilled(FILL_RADAR);

        if (!showBackground) {
            // Set the background of the picture to white
            retChart.setBackgroundPaint(Color.WHITE);

            // Set the border of the plot to white
            plot.setOutlinePaint(Color.WHITE);
        }
        super.setChart(retChart);
    }
    return retChart;
}

From source file:org.jstockchart.plot.TimeseriesPlot.java

private XYPlot createPricePlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    PriceArea priceArea = timeseriesArea.getPriceArea();
    Color averageColor = new Color(243, 182, 117);
    priceArea.setAverageColor(averageColor);
    priceArea.setPriceColor(Color.BLUE);
    TimeSeriesCollection priceDataset = new TimeSeriesCollection();
    priceDataset.addSeries(dataset.getPriceTimeSeries().getTimeSeries());
    if (priceArea.isAverageVisible()) {
        priceDataset.addSeries(dataset.getAverageTimeSeries().getTimeSeries());
    }/*w  w w  . java 2  s  .c o m*/

    CentralValueAxis logicPriceAxis = priceArea.getLogicPriceAxis();

    logicPriceAxis.setTickCount(7);

    CFXNumberAxis priceAxis = new CFXNumberAxis(logicPriceAxis.getLogicTicks());
    priceAxis.setShowUD(true);
    priceAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue());
    priceAxis.setTickMarksVisible(false);
    XYLineAndShapeRenderer priceRenderer = new XYLineAndShapeRenderer(true, false);
    priceAxis.setUpperBound(logicPriceAxis.getUpperBound());
    priceAxis.setLowerBound(logicPriceAxis.getLowerBound());
    priceAxis.setAxisLineVisible(false);
    priceAxis.setTickLabelFont(axisFont);
    priceRenderer.setSeriesPaint(0, priceArea.getPriceColor());
    priceRenderer.setSeriesPaint(1, priceArea.getAverageColor());

    CFXNumberAxis rateAxis = new CFXNumberAxis(logicPriceAxis.getRatelogicTicks());
    rateAxis.setShowUD(true);
    rateAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue());
    rateAxis.setTickMarksVisible(false);
    ;
    rateAxis.setTickLabelFont(axisFont);
    rateAxis.setAxisLineVisible(false);
    rateAxis.setUpperBound(logicPriceAxis.getUpperBound());
    rateAxis.setLowerBound(logicPriceAxis.getLowerBound());
    XYPlot plot = new XYPlot(priceDataset, null, priceAxis, priceRenderer);
    plot.setBackgroundPaint(priceArea.getBackgroudColor());
    plot.setOrientation(priceArea.getOrientation());
    plot.setRangeAxisLocation(priceArea.getPriceAxisLocation());
    plot.setRangeMinorGridlinesVisible(false);

    Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
            new float[] { 2.0f, 2.0f }, 1.0f);

    plot.setRangeGridlineStroke(gridLineStroke);
    plot.setDomainGridlineStroke(gridLineStroke);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setOutlineVisible(true);
    plot.setOutlineStroke(outLineStroke);
    plot.setOutlinePaint(Color.BLACK);

    if (priceArea.isRateVisible()) {
        plot.setRangeAxis(1, rateAxis);
        plot.setRangeAxisLocation(1, priceArea.getRateAxisLocation());
        plot.setDataset(1, null);
        plot.mapDatasetToRangeAxis(1, 1);
    }

    if (priceArea.isMarkCentralValue()) {
        Number centralPrice = logicPriceAxis.getCentralValue();
        if (centralPrice != null) {
            plot.addRangeMarker(new ValueMarker(centralPrice.doubleValue(), priceArea.getCentralPriceColor(),
                    new BasicStroke()));
        }
    }
    return plot;
}

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

public void init() {
    CLEAR_BUTTON = false;/* w  w  w  .  j  a v a  2 s .c  o  m*/
    LEGEND_SWITCH = false;
    //DefaultDrawingSupplier supplier = new DefaultDrawingSupplier();
    DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    //series_shapes = supplier.createStandardSeriesShapes();

    //color_mainGroup = supplier.getNextPaint(); //moved to EM
    for (int i = 0; i < 10; i++) {
        //color_kernels[i] = supplier.getNextPaint();
        //series_strokes[i] = supplier.getNextStroke();
        series_shapes[i] = supplier.getNextShape();
    }

    series_strokes[0] = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);

    series_strokes[1] = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);

    series_strokes[2] = new BasicStroke(3.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);

    series_strokes[3] = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f);
    series_strokes[4] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f);

    series_strokes[5] = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 10.0f, 6.0f }, 0.0f);
    series_strokes[6] = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f);
    series_strokes[7] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f);
    series_strokes[8] = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 6.0f }, 0.0f);

    series_strokes[9] = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 2.0f, 6.0f }, 0.0f);

    controlPanel = new JPanel();
    modelAllSelected = TOGETHER;
    num_series = 1;
    mEMexperiment = new MixtureEMExperiment[num_series];
    mEMexperiment[0] = new MixtureEMExperiment();
    resultsTables = new CustomJTable[num_series];
    resultsTables[0] = mEMexperiment[0].getResultsTable();

    initControlPanel();
    //initResutlsTable();
    SHOW_STATUS_TEXTAREA = false;

    super.init();

    indLabel = new JLabel("X");
    depLabel = new JLabel("Y");

    mEMexperiment[0].resetSize();

    packControlArea();
}

From source file:net.praqma.jenkins.memorymap.MemoryMapBuildAction.java

public void doDrawMemoryMapUsageGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
    DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dataset = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>();

    String members = req.getParameter("categories");
    String graphTitle = req.getParameter("title");

    int w = Integer.parseInt(req.getParameter("width"));
    int h = Integer.parseInt(req.getParameter("height"));

    List<String> memberList = Arrays.asList(members.split(","));
    List<List<String>> memberLists = new ArrayList<List<String>>();

    for (String s : memberList) {
        memberLists.add(Arrays.asList(s.split(" ")));
    }//from ww  w  .  java 2s .co m

    List<ValueMarker> markers = new ArrayList<ValueMarker>();

    double max = Double.MIN_VALUE;
    Set<String> drawnMarker = new HashSet<String>();

    String scale = getRecorder().scale;

    for (MemoryMapBuildAction membuild = this; membuild != null; membuild = membuild.getPreviousAction()) {
        ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(membuild.build);
        MemoryMapConfigMemory result = membuild.getMemoryMapConfig();
        MemoryMapConfigMemory resultBlacklist = new MemoryMapConfigMemory();
        for (List<String> list : memberLists) {
            double value = 0.0d;
            double maxx = 0.0d;
            String labelName = "";
            for (MemoryMapConfigMemoryItem res : result) {
                if (list.contains(res.getName()) && !resultBlacklist.contains(res)) {
                    resultBlacklist.add(res);
                    if (labelName.equals("")) {
                        labelName = res.getName();
                    } else {
                        labelName = String.format("%s+%s", labelName, res.getName());
                    }

                    if (getRecorder().getShowBytesOnGraph()) {
                        maxx = maxx + HexUtils.byteCount(res.getLength(), getRecorder().getWordSize(), scale);
                        value = value + HexUtils.byteCount(res.getUsed(), getRecorder().getWordSize(), scale);
                    } else {
                        maxx = maxx + HexUtils.wordCount(res.getLength(), getRecorder().getWordSize(), scale);
                        value = value + HexUtils.wordCount(res.getUsed(), getRecorder().getWordSize(), scale);
                    }
                } else {
                }

                if (maxx > max) {
                    max = maxx;
                }
                if (value > max) {
                    max = value;
                }
            }
            if (!labelName.equals("")) {
                dataset.add(value, labelName, label);
            }

            boolean makeMarker = true;
            for (ValueMarker vm : markers) {
                if (maxx == vm.getValue() && !vm.getLabel().contains(labelName) && !labelName.equals("")) {
                    drawnMarker.add(vm.getLabel().replace("(MAX) - ", "") + " - " + labelName);
                    String s = vm.getLabel().replace("(MAX) - ", "");

                    vm.setLabel(String.format("%s - %s", vm.getLabel(), labelName));
                    //this is the size of chars used for setting the offset right
                    double i = vm.getLabel().length() * labelOffset + 40;
                    vm.setLabelOffset(new RectangleInsets(5, i, -20, 5));

                    makeMarker = false;
                }
            }

            if ((!labelName.equals("")) && (drawnMarker.add(labelName))) {
                if (makeMarker) {
                    ValueMarker vm = new ValueMarker((double) maxx, Color.BLACK,
                            new BasicStroke(1.2f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1.0f,
                                    new float[] { 6.0f, 6.0f }, 0.0f));

                    vm.setLabel(String.format("(MAX) - %s", labelName));

                    double i = vm.getLabel().length() * labelOffset + 40;
                    vm.setLabelOffset(new RectangleInsets(5, i, -20, 5));
                    vm.setLabelAnchor(RectangleAnchor.TOP_LEFT);
                    vm.setPaint(Color.BLACK);
                    vm.setOutlinePaint(Color.BLACK);
                    vm.setAlpha(1.0f);
                    markers.add(vm);
                }
            }
        }
    }

    String s = "";
    if (scale.equalsIgnoreCase("kilo")) {
        s = "k";
    } else if (scale.equalsIgnoreCase("mega")) {
        s = "M";
    } else if (scale.equalsIgnoreCase("giga")) {
        s = "G";
    }

    String byteLegend = s + "Bytes";
    String wordLegend = s + "Words";

    String legend = getRecorder().getShowBytesOnGraph() ? byteLegend : wordLegend;

    JFreeChart chart = createPairedBarCharts(graphTitle, legend, max * 1.1d, 0d, dataset.build(), markers);

    chart.setBackgroundPaint(Color.WHITE);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    ChartUtil.generateGraph(req, rsp, chart, w, h);
}

From source file:org.tsho.dmc2.core.chart.TrajectoryMultiRenderer.java

public LegendItemCollection getLegendItems() {

    Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    Shape shape = new Rectangle2D.Double(-3, -3, 6, 6);

    LegendItemCollection legendItems = new LegendItemCollection();

    for (int i = 0; i < stepperList.length; i++) {
        legendItems.add(new LegendItem(Integer.toString(i), "", shape, true, paintList[i], stroke, Color.yellow,
                stroke));/*from   www.  java  2s . c o m*/
    }

    return legendItems;
}