Example usage for org.jfree.chart.plot XYPlot setRangeMinorGridlinesVisible

List of usage examples for org.jfree.chart.plot XYPlot setRangeMinorGridlinesVisible

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRangeMinorGridlinesVisible.

Prototype

public void setRangeMinorGridlinesVisible(boolean visible) 

Source Link

Document

Sets the flag that controls whether or not the range axis minor grid lines are visible.

Usage

From source file:org.spf4j.perf.impl.chart.Charts.java

public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values,
        final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
    final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis,
            stepMillis);//from   w  w w .  jav  a  2s . c  o m
    NumberAxis xAxis = new NumberAxis("Time");
    xAxis.setStandardTickUnits(dataSet.createXTickUnits());
    xAxis.setLowerMargin(0);
    xAxis.setUpperMargin(0);
    xAxis.setVerticalTickLabels(true);
    NumberAxis yAxis = new NumberAxis(uom);
    yAxis.setStandardTickUnits(dataSet.createYTickUnits());
    yAxis.setLowerMargin(0);
    yAxis.setUpperMargin(0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    PaintScale scale;
    if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
        if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
            scale = new InverseGrayScale(0, 1);
        } else {
            scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
        }
    } else {
        scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
    }
    renderer.setPaintScale(scale);
    renderer.setBlockWidth(1);
    renderer.setBlockHeight(1);
    XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);
    JFreeChart chart = new JFreeChart(chartName, plot);
    PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
    legend.setMargin(0, 5, 0, 5);
    chart.addSubtitle(legend);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo2.java

private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {
    JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo2", "X", "Y", dataset);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");

    plot.setDomainPannable(true);/*from  w w  w  .j a v  a 2s .  c o  m*/
    plot.setRangePannable(true);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setSeriesFillPaint(0, r.lookupSeriesPaint(0));
    r.setSeriesFillPaint(1, r.lookupSeriesPaint(1));
    r.setSeriesFillPaint(2, r.lookupSeriesPaint(2));
    r.setUseFillPaint(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(2.0f);
    domainAxis.setMinorTickMarksVisible(true);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(2.0f);
    rangeAxis.setMinorTickMarksVisible(true);

    //add selection specific rendering
    IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}

From source file:org.jfree.expdemo.SelectionDemo2.java

private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo2", "X", "Y", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");

    plot.setDomainPannable(true);/*from   w  w  w.  j a va  2 s .c  o  m*/
    plot.setRangePannable(true);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setSeriesFillPaint(0, r.lookupSeriesPaint(0));
    r.setSeriesFillPaint(1, r.lookupSeriesPaint(1));
    r.setSeriesFillPaint(2, r.lookupSeriesPaint(2));
    r.setUseFillPaint(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(2.0f);

    domainAxis.setMinorTickCount(2);
    domainAxis.setMinorTickMarksVisible(true);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(2.0f);
    rangeAxis.setMinorTickCount(2);
    rangeAxis.setMinorTickMarksVisible(true);

    //add selection specific rendering
    IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white);

    //register plot as selection change listener
    ext.addSelectionChangeListener(plot);

    return chart;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo3.java

private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {
    JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo3", "X", "Y", dataset);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");

    plot.setDomainPannable(true);//from  w w  w.j a  v  a  2s .  c  o  m
    plot.setRangePannable(true);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    //XYItemRenderer r = plot.getRenderer();
    XYDotRenderer r = new XYDotRenderer();
    r.setDotHeight(2);
    r.setDotWidth(2);

    r.setSeriesPaint(0, Color.blue);
    r.setSeriesPaint(1, Color.green);
    r.setSeriesPaint(2, Color.yellow);
    r.setSeriesPaint(3, Color.orange);
    plot.setRenderer(r);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(2.0f);

    domainAxis.setMinorTickMarksVisible(true);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(2.0f);
    rangeAxis.setMinorTickMarksVisible(true);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(r, ext, Color.red);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}

From source file:org.jfree.expdemo.SelectionDemo3.java

private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo3", "X", "Y", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");

    plot.setDomainPannable(true);/*  w w  w .  java2s  .c  o  m*/
    plot.setRangePannable(true);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    //XYItemRenderer r = plot.getRenderer();
    XYDotRenderer r = new XYDotRenderer();
    r.setDotHeight(2);
    r.setDotWidth(2);

    r.setSeriesPaint(0, Color.blue);
    r.setSeriesPaint(1, Color.green);
    r.setSeriesPaint(2, Color.yellow);
    r.setSeriesPaint(3, Color.orange);
    plot.setRenderer(r);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(2.0f);

    domainAxis.setMinorTickCount(2);
    domainAxis.setMinorTickMarksVisible(true);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(2.0f);
    rangeAxis.setMinorTickCount(2);
    rangeAxis.setMinorTickMarksVisible(true);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(r, ext, Color.red);

    //register plot as selection change listener
    ext.addSelectionChangeListener(plot);

    return chart;
}

From source file:classpackage.ChartGalaxy.java

private static JFreeChart createChart(final XYDataset dataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("MDS Galaxy", "X", "Y", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setBaseItemLabelGenerator(new LabelGenerator());
    renderer.setBaseItemLabelPaint(Color.WHITE);//label
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(15f));
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

    //set false para linhas no grafico
    xyPlot.setDomainGridlinesVisible(false);
    xyPlot.setRangeGridlinesVisible(false);
    xyPlot.setRangeMinorGridlinesVisible(false);
    xyPlot.setRangeCrosshairVisible(false);
    xyPlot.setRangeCrosshairLockedOnData(false);
    xyPlot.setRangeZeroBaselineVisible(false);
    xyPlot.setBackgroundPaint(Color.BLACK);
    double size = 40.0;
    double delta = size / 2.0;
    Shape shape = new Rectangle2D.Double(-delta, -delta, size, size);

    renderer.setSeriesShape(0, shape);/*from   w  w  w  . j  a  va 2  s .c  om*/
    renderer.setSeriesPaint(0, transparent);

    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setRange(-0.1, 0.1);
    domain.setTickUnit(new NumberTickUnit(0.1));
    domain.setVerticalTickLabels(true);
    NumberAxis range = (NumberAxis) xyPlot.getRangeAxis();
    range.setRange(-0.1, 0.1);
    range.setTickUnit(new NumberTickUnit(0.1));

    return jfreechart;
}

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());
    }/*from ww  w  .  ja va2s  .  co  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:org.jstockchart.plot.TimeseriesPlot.java

private XYPlot createVolumePlot() {
    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);
    VolumeArea volumeArea = timeseriesArea.getVolumeArea();
    LogicNumberAxis logicVolumeAxis = volumeArea.getLogicVolumeAxis();
    Color volumeColor = new Color(86, 126, 160);
    volumeArea.setVolumeColor(volumeColor);
    CFXNumberAxis volumeAxis = new CFXNumberAxis(logicVolumeAxis.getLogicTicks());
    volumeAxis.setAxisLineVisible(false);
    volumeAxis.setCustomTickCount(2);//from  w ww . j a  va  2 s  . co  m
    volumeAxis.setTickLabelPaint(volumeColor);
    volumeAxis.setUpperBound(logicVolumeAxis.getUpperBound());
    volumeAxis.setTickLabelFont(axisFont);
    volumeAxis.setTickMarkStroke(stroke);
    volumeAxis.setLowerBound(logicVolumeAxis.getLowerBound());
    volumeAxis.setAutoRangeIncludesZero(true);
    XYAreaRenderer2 volumeRenderer = new XYAreaRenderer2();
    volumeRenderer.setSeriesPaint(0, volumeArea.getVolumeColor());
    //volumeRenderer.setShadowVisible(false);
    volumeRenderer.setSeriesStroke(0, stroke);
    volumeRenderer.setBaseStroke(stroke);
    XYPlot plot = new XYPlot(new TimeSeriesCollection(dataset.getVolumeTimeSeries()), null, volumeAxis,
            volumeRenderer);
    plot.setBackgroundPaint(volumeArea.getBackgroudColor());
    plot.setOrientation(volumeArea.getOrientation());
    plot.setRangeAxisLocation(volumeArea.getVolumeAxisLocation());
    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.setBackgroundPaint(Color.RED);
    plot.setRangeGridlineStroke(gridLineStroke);
    plot.setDomainGridlineStroke(gridLineStroke);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setOutlineVisible(true);
    plot.setOutlineStroke(outLineStroke);
    plot.setOutlinePaint(Color.black);
    plot.setRangeZeroBaselineVisible(true);
    return plot;
}

From source file:org.owasp.benchmark.score.report.Scatter.java

private JFreeChart display(String title, int height, int width, OverallResults or) {
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Note: this is a little weird, since each point is a separate series
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (OverallResult r : or.getResults()) {
        series.add(r.fpr * 100, r.tpr * 100);
    }//from w ww . j a  v  a  2s  .c o  m
    dataset.addSeries(series);

    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-9.99, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String letter = "" + ((String)dataset.getSeries(i).getKey()).charAt(0);
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(letter); 
    //            renderer.setSeriesItemLabelGenerator(i, generator); 
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(or, xyplot);
    makeLegend(or, 57, 48, dataset, xyplot);

    // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 },
            0);
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse = makePointer(75, 0, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6);
    time.setTextAnchor(TextAnchor.TOP_LEFT);
    time.setFont(theme.getRegularFont());
    time.setPaint(Color.red);
    xyplot.addAnnotation(time);

    XYTextAnnotation stroketext = new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);
    return chart;
}

From source file:org.owasp.benchmark.score.report.ScatterScores.java

private JFreeChart display(String title, int height, int width, List<Report> toolResults) {
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
        Report toolReport = toolResults.get(i);
        OverallResults overallResults = toolReport.getOverallResults();
        series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
    }//from  www  .j  av  a 2  s. c  o m
    dataset.addSeries(series);

    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); 
    //            renderer.setSeriesItemLabelGenerator(i, generator); 
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(toolResults, xyplot);
    makeLegend(toolResults, 57, 48, dataset, xyplot);

    Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 },
            0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
        double x = item.getX().doubleValue();
        double y = item.getY().doubleValue();
        double z = (x + y) / 2;
        XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
        xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext = new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);
    return chart;
}