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

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

Introduction

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

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

From source file:networkmonitor.MainIBMApplicationForm.java

/**
 * Creates a chart.//from ww w .  j a  v a 2  s.  co  m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(

            // put a big space or it'll overlap with the statistics of data...  :) 
            "B/W Usage in KBps:                                                                    ", // chart title
            "Seconds                    ", // x axis label
            "  Usage", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, // Plot Orientation.. it means grap will show you statistics vertically 
            true, // include legend
            true, // tooltips
            false // urls
    );

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

    // Background color of chart/outside plot........
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    //plot background color inside the graph....
    plot.setBackgroundPaint(Color.orange); //org.jfree.chart.plot.XYPlot;
    //Plot vertical inner graph line.....
    plot.setDomainGridlinePaint(Color.red);
    //plot horizontal inner graph line.....
    plot.setRangeGridlinePaint(Color.blue);

    //Sets the renderer for the PGraphics object that is used for drawing to...
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    // it used to show the up and down connecting line will show or not(RED LINE of graph)
    renderer.setSeriesLinesVisible(1, true);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);//it used to show the up and down block of data(RED Block Of GRAPH)

    //......................................... 

    //..... change the auto tick unit selection to integer units only
    //LIMIT OF X and Y axis GRAPH SIDE DATA (usages/second)
    //.....if I unhide these then only integer number show in X axis,it avoid floating point

    /*final NumberAxis domainAxis = new NumberAxis("X-Axis");
    domainAxis.setRange(0.00,1.00);
     domainAxis.setTickUnit(new NumberTickUnit(0.1));
     final NumberAxis rangeAxis = new NumberAxis("Y-Axis");
      rangeAxis.setRange(0.0,1.0);
     rangeAxis.setTickUnit(new NumberTickUnit(0.0));*/

    //usases(X axis) integer data counting
    //final NumberAxis rangeAxis = (NumberAxis) 
    //plot.getRangeAxis();
    //  rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    //..............................................

    return chart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            xydataset, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);/*  w w  w  .  j a va 2 s  .c  om*/
    xyplot.setRangePannable(true);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setLowerMargin(0.20000000000000001D);
    dateaxis.setUpperMargin(0.20000000000000001D);
    dateaxis.setStandardTickUnits(createStandardDateTickUnits());
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setLowerMargin(0.20000000000000001D);
    numberaxis.setUpperMargin(0.20000000000000001D);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseLinesVisible(true);
    xylineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    xylineandshaperenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1, 5F, new float[] { 10F, 5F }, 0.0F));
    xylineandshaperenderer.setSeriesFillPaint(0, Color.white);
    xylineandshaperenderer.setSeriesFillPaint(1, Color.white);
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xylineandshaperenderer.setDefaultEntityRadius(6);
    xylineandshaperenderer.addAnnotation(new XYDrawableAnnotation((new Month(4, 2005)).getFirstMillisecond(),
            600D, 180D, 100D, 3D, createPieChart()));
    xylineandshaperenderer.addAnnotation(new XYDrawableAnnotation((new Month(9, 2007)).getFirstMillisecond(),
            1250D, 120D, 100D, 2D, createBarChart()));
    xyplot.setRenderer(xylineandshaperenderer);
    return jfreechart;
}

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

/**
 * Creates a chart.//from  ww  w  .  j a  va 2  s .  c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Daylight Hours - London, UK", "Date", "Time",
            dataset, true, // legend
            true, // tool tips
            false // URLs
    );
    chart.setBackgroundPaint(Color.white);

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer(Color.blue, Color.blue, false);
    renderer.setStroke(new BasicStroke(2.0f));
    renderer.setSeriesPaint(0, Color.yellow);
    renderer.setSeriesPaint(1, Color.red);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final DateAxis domainAxis = new DateAxis("Time");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    final Color c = new Color(255, 60, 24, 63);
    final Marker bst = new IntervalMarker(new Day(28, 3, 2004).getFirstMillisecond(),
            new Day(30, 10, 2004).getFirstMillisecond(), c, new BasicStroke(2.0f), null, null, 1.0f);
    bst.setLabel("British Summer Time");
    bst.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
    bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, 10));
    bst.setLabelTextAnchor(TextAnchor.BASELINE_RIGHT);
    plot.addDomainMarker(bst, Layer.BACKGROUND);

    final DateAxis rangeAxis = new DateAxis("Time");
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    plot.setRangeAxis(rangeAxis);
    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates and returns a default instance of a candlesticks chart.    
 *    // w  w w .  jav a2  s .  com
 * @param title  the chart title (<code>null</code> permitted).    
 * @param timeAxisLabel  a label for the time axis (<code>null</code>     
 *                       permitted).    
 * @param valueAxisLabel  a label for the value axis (<code>null</code>     
 *                        permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 *    
 * @return A candlestick chart.    
 */
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel,
        OHLCDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}

From source file:weka.gui.beans.JFreeChartOffscreenChartRenderer.java

/**
 * Render an XY scatter plot/*  w  ww.  j a v  a  2s  .  c o m*/
 * 
 * @param width the width of the resulting chart in pixels
 * @param height the height of the resulting chart in pixels
 * @param series a list of Instances - one for each series to be plotted
 * @param xAxis the name of the attribute for the x-axis (all series Instances
 *          are expected to have an attribute of the same type with this name)
 * @param yAxis the name of the attribute for the y-axis (all series Instances
 *          are expected to have an attribute of the same type with this name)
 * @param optionalArgs optional arguments to the renderer (may be null)
 * 
 * @return a BufferedImage containing the chart
 * @throws Exception if there is a problem rendering the chart
 */
public BufferedImage renderXYScatterPlot(int width, int height, List<Instances> series, String xAxis,
        String yAxis, List<String> optionalArgs) throws Exception {

    String plotTitle = "Scatter Plot";
    String userTitle = getOption(optionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
    String colorAtt = getOption(optionalArgs, "-color");

    if (series.size() == 1 && colorAtt != null && colorAtt.length() > 0) {
        int colIndex = getIndexOfAttribute(series.get(0), colorAtt);
        if (colIndex >= 0 && series.get(0).attribute(colIndex).isNominal()) {
            // split single series out into multiple instances objects - one
            // per class
            series = splitToClasses(series.get(0), colIndex);
            for (Instances insts : series) {
                insts.setClassIndex(colIndex);
            }
        }
    }

    Instances masterInstances = series.get(0);
    int xAx = getIndexOfAttribute(masterInstances, xAxis);
    int yAx = getIndexOfAttribute(masterInstances, yAxis);
    if (xAx < 0) {
        xAx = 0;
    }
    if (yAx < 0) {
        yAx = 0;
    }

    // Set the axis names just in case we've been supplied with
    // /first, /last or /<num>
    xAxis = masterInstances.attribute(xAx).name();
    yAxis = masterInstances.attribute(yAx).name();

    // look for an additional attribute that stores the
    // shape sizes - could be either nominal or numeric errors.
    // We only use numeric error information
    String shapeSize = getOption(optionalArgs, "-shapeSize");

    boolean nominalClass = (masterInstances.classIndex() >= 0 && masterInstances.classAttribute().isNominal());

    int shapeSizeI = -1;
    if (shapeSize != null && shapeSize.length() > 0) {
        shapeSizeI = getIndexOfAttribute(masterInstances, shapeSize);
    }

    AbstractIntervalXYDataset xyDataset = null;

    if (shapeSizeI < 0 || nominalClass) {
        xyDataset = new XYSeriesCollection();
    } else {
        xyDataset = new XYIntervalSeriesCollection();
    }
    // add master series
    Series master = null;

    if (shapeSizeI < 0 || nominalClass) {
        master = new XYSeries(masterInstances.relationName());
    } else {
        master = new XYIntervalSeries(masterInstances.relationName());
    }
    AttributeStats xStats = masterInstances.attributeStats(xAx);
    AttributeStats yStats = masterInstances.attributeStats(yAx);
    double sizeRange = 0;
    double sizeMin = 0;
    if (shapeSizeI >= 0 && !nominalClass) {
        AttributeStats sStats = masterInstances.attributeStats(shapeSizeI);
        sizeRange = sStats.numericStats.max - sStats.numericStats.min;
        sizeMin = sStats.numericStats.min;
    }
    double xRange = 0;
    if (masterInstances.attribute(xAx).isNominal()) {
        xRange = masterInstances.attribute(xAx).numValues();
    } else {
        xRange = xStats.numericStats.max - xStats.numericStats.min;
    }
    double yRange = 0;
    if (masterInstances.attribute(yAx).isNominal()) {
        xRange = masterInstances.attribute(yAx).numValues();
    } else {
        yRange = yStats.numericStats.max - yStats.numericStats.min;
    }
    for (int i = 0; i < masterInstances.numInstances(); i++) {
        Instance inst = masterInstances.instance(i);
        if (!inst.isMissing(xAx) && !inst.isMissing(yAx)) {
            if (shapeSizeI < 0 || nominalClass) {
                ((XYSeries) master).add(inst.value(xAx), inst.value(yAx));
            } else {
                double xBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange;
                xBar *= (xRange / 5.0); // max of 1/5th the x range
                double yBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange;
                yBar *= (yRange / 5.0);
                double x = inst.value(xAx);
                double y = inst.value(yAx);
                ((XYIntervalSeries) master).add(x, x - (xBar / 2.0), x + (xBar / 2.0), y, y - (yBar / 2.0),
                        y + (yBar / 2.0));
            }
        }
    }

    if (shapeSizeI < 0 || nominalClass) {
        ((XYSeriesCollection) xyDataset).addSeries((XYSeries) master);
    } else {
        ((XYIntervalSeriesCollection) xyDataset).addSeries((XYIntervalSeries) master);
    }

    // remaining series
    for (int i = 1; i < series.size(); i++) {
        Instances aSeriesI = series.get(i);
        Series aSeriesJ = null;
        if (shapeSizeI < 0 || nominalClass) {
            aSeriesJ = new XYSeries(aSeriesI.relationName());
        } else {
            aSeriesJ = new XYIntervalSeries(aSeriesI.relationName());
        }
        for (int j = 0; j < aSeriesI.numInstances(); j++) {
            Instance inst = aSeriesI.instance(j);
            if (!inst.isMissing(xAx) && !inst.isMissing(yAx)) {
                if (shapeSizeI < 0 || nominalClass) {
                    ((XYSeries) aSeriesJ).add(inst.value(xAx), inst.value(yAx));
                } else {
                    double xBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange;
                    xBar *= (xRange / 5.0); // max of 1/10th the x range
                    double yBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange;
                    yBar *= (yRange / 5.0);
                    double x = inst.value(xAx);
                    double y = inst.value(yAx);
                    ((XYIntervalSeries) aSeriesJ).add(x, x - (xBar / 2.0), x + (xBar / 2.0), y,
                            y - (yBar / 2.0), y + (yBar / 2.0));
                }
            }
        }

        if (shapeSizeI < 0 || nominalClass) {
            ((XYSeriesCollection) xyDataset).addSeries((XYSeries) aSeriesJ);
        } else {
            ((XYIntervalSeriesCollection) xyDataset).addSeries((XYIntervalSeries) aSeriesJ);
        }
    }

    JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xAxis, yAxis, xyDataset,
            PlotOrientation.VERTICAL, true, false, false);
    chart.setBackgroundPaint(java.awt.Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (shapeSizeI < 0 || nominalClass) {
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
        renderer.setBaseShapesFilled(false);
        plot.setRenderer(renderer);
    } else {
        XYErrorRenderer renderer = new XYErrorRenderer();
        renderer.setDrawXError(true);
        renderer.setDrawYError(true);
        renderer.setBaseLinesVisible(false);
        plot.setRenderer(renderer);
    }

    BufferedImage image = chart.createBufferedImage(width, height);

    return image;
}

From source file:eu.choreos.chart.XYChart.java

private JFreeChart createChart(XYDataset dataset, String chartTitle) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "Execution size", // domain axis label
            "Range", // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w  ww  .j a v a 2s. c o m*/

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates a stepped XY plot with default settings.    
 *    //from ww w  . j a va 2s . c  om
 * @param title  the chart title (<code>null</code> permitted).    
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).    
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param orientation  the plot orientation (horizontal or vertical)     
 *                     (<code>null</code> NOT permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 * @param tooltips  configure chart to generate tool tips?    
 * @param urls  configure chart to generate URLs?    
 *    
 * @return A chart.    
 */
public static JFreeChart createXYStepChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    DateAxis xAxis = new DateAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates a filled stepped XY plot with default settings.    
 *    //w  w  w.ja va2 s .  com
 * @param title  the chart title (<code>null</code> permitted).    
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).    
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param orientation  the plot orientation (horizontal or vertical)     
 *                     (<code>null</code> NOT permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 * @param tooltips  configure chart to generate tool tips?    
 * @param urls  configure chart to generate URLs?    
 *    
 * @return A chart.    
 */
public static JFreeChart createXYStepAreaChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator,
            urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;
}

From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

private JFreeChart createChart(XYDataset data) {
    ValueAxis timeAxis = new DateAxis("Date/Time");
    timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
    timeAxis.setUpperMargin(0.02);// www. java2  s . c o  m
    NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);
    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null, null));
    JFreeChart chart = new JFreeChart("Cookie values over time", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    return chart;
}

From source file:me.childintime.childintime.ui.window.tool.BmiToolDialog.java

/**
 * Creates a chart.// ww  w .j  ava 2 s .c om
 *
 * @param dataset  the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    // Create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("BMI chart", "Age", "Value", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // Set the background color to the LAF's default
    chart.setBackgroundPaint(new JPanel().getBackground());

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < 3; i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesFillPaint(i, Color.RED);
    }
    plot.setRenderer(renderer);

    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}