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

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

Introduction

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

Prototype

public void setDomainGridlinePaint(Paint paint) 

Source Link

Document

Sets the paint for the grid lines plotted against the domain axis, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:edu.mit.fss.examples.member.gui.PowerSubsystemPanel.java

/**
 * Instantiates a new power subsystem panel for a subsystem.
 *
 * @param subsystem the subsystem/*from   w w  w. j a  v  a2  s .  co  m*/
 */
public PowerSubsystemPanel(SpacePowerSubsystem subsystem) {
    this.subsystem = subsystem;

    logger.trace("Creating and adding energy storage chart panel.");
    storageDataset = new TimeSeriesCollection();
    storageSeries = new TimeSeries("Storage");
    storageDataset.addSeries(storageSeries);
    storageChart = ChartFactory.createTimeSeriesChart(null, "Time", "Stored Energy (W-hr)", storageDataset,
            false, false, false);
    storageChart.setBackgroundPaint(getBackground());
    if (storageChart.getPlot() instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) storageChart.getPlot();
        XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
        renderer.setSeriesShape(0, new Ellipse2D.Double(-2, -2, 4, 4));
        xyPlot.setRenderer(renderer);
        xyPlot.setBackgroundPaint(Color.WHITE);
        xyPlot.setDomainGridlinePaint(Color.GRAY);
        xyPlot.setRangeGridlinePaint(Color.GRAY);
    }
    addTab("Storing", new ChartPanel(storageChart));

    logger.trace("Creating and adding energy transformation chart panel.");
    powerDataset = new TimeSeriesCollection();
    generationSeries = new TimeSeries("Generation");
    powerDataset.addSeries(generationSeries);
    consumptionSeries = new TimeSeries("Consumption");
    powerDataset.addSeries(consumptionSeries);
    powerChart = ChartFactory.createTimeSeriesChart(null, "Time", "Power (W)", powerDataset, true, false,
            false);
    powerChart.setBackgroundPaint(getBackground());
    if (powerChart.getPlot() instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) powerChart.getPlot();
        XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
        renderer.setSeriesShape(0, new Ellipse2D.Double(-2, -2, 4, 4));
        renderer.setSeriesPaint(0, Color.red);
        renderer.setSeriesShape(1, new Ellipse2D.Double(-2, -2, 4, 4));
        renderer.setSeriesPaint(1, Color.green);
        xyPlot.setRenderer(renderer);
        xyPlot.setBackgroundPaint(Color.WHITE);
        xyPlot.setDomainGridlinePaint(Color.GRAY);
        xyPlot.setRangeGridlinePaint(Color.GRAY);
    }
    JPanel chartPanel = new JPanel(new BorderLayout());
    chartPanel.add(new ChartPanel(powerChart), BorderLayout.CENTER);
    chartPanel.add(new JButton(exportAction), BorderLayout.SOUTH);
    addTab("Transforming", chartPanel);
}

From source file:correlation.and.regression.analysis.MainWindow.java

private void showCorrelationField() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries correlation = new XYSeries("Correlation Field");
    for (int i = 0; i < arr[0].countOfNumbers; i++) {
        //XYSeries tmp = new XYSeries(""+i);
        correlation.add(arr[0].getNumber(i), arr[1].getNumber(i));
        //tmp.add(arr[0].getNumber(i), arr[1].getNumber(i));
        //dataset.addSeries(tmp);
    }//from  w w w  . j  ava  2 s. com
    dataset.addSeries(correlation);
    XYSeries regr = StaticFunctions.drawRegressionLine(arr[0], arr[1]);
    dataset.addSeries(regr);

    XYSeries ConfidenceIntervalMax = StaticFunctions.drawConfidenceIntervalMax(arr[0], arr[1]);
    dataset.addSeries(ConfidenceIntervalMax);
    XYSeries ConfidenceIntervalMin = StaticFunctions.drawConfidenceIntervalMin(arr[0], arr[1]);
    dataset.addSeries(ConfidenceIntervalMin);

    XYSeries Confidence2IntervalMax = StaticFunctions.drawConfidence2IntervalMax(arr[0], arr[1]);
    dataset.addSeries(Confidence2IntervalMax);
    XYSeries Confidence2IntervalMin = StaticFunctions.drawConfidence2IntervalMin(arr[0], arr[1]);
    dataset.addSeries(Confidence2IntervalMin);

    XYSeries TolerantIntervalMax = StaticFunctions.drawTolerantIntervalMax(arr[0], arr[1]);
    dataset.addSeries(TolerantIntervalMax);
    XYSeries TolerantIntervalMin = StaticFunctions.drawTolerantIntervalMin(arr[0], arr[1]);
    dataset.addSeries(TolerantIntervalMin);
    JFreeChart chart = ChartFactory.createXYLineChart("Relation", "X", "Y", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesShapesVisible(4, false);
    renderer.setSeriesShapesVisible(5, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChP = new ChartPanel(chart);
    ChP.setSize(jSPanelChart.getWidth(), jSPanelChart.getHeight());
    jSPanelChart.removeAll();
    jSPanelChart.revalidate();
    jSPanelChart.add(ChP);
    jSPanelChart.repaint();
}

From source file:Servlet3.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/* ww  w .  j a v  a 2s .co m*/
        System.out.println("inside servlet");
        String a = request.getParameter("countryf");
        String c = request.getParameter("submit");
        String b = request.getParameter("paramf");

        String CurentUID = request.getParameter("UIDvalue2f");
        String URLRequest = request.getRequestURL().append('?').append(request.getQueryString()).toString();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 1);
        SimpleDateFormat format1 = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy");
        String date1 = cal.getTime().toString();

        System.out.println("inside servlet");

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:server");

        // To Insert data to UserActivity table for Recent Activities Tab
        Statement sthistoryinsert3 = con.createStatement();
        String insertstring = "Insert into UserActivity values('" + CurentUID + "','" + date1
                + "','Future Data Forecast','" + a + "','" + b + "','" + URLRequest + "')";
        sthistoryinsert3.executeUpdate(insertstring);
        sthistoryinsert3.close();
        System.out.println("\n Step 1");
        Statement st = con.createStatement();
        XYSeriesCollection dataset = new XYSeriesCollection();
        XYSeries series = new XYSeries(b);

        String query = "SELECT [2000],[2012] FROM country where CountryName='" + a + "' AND SeriesName='" + b
                + "'";
        System.out.println(query);
        ResultSet rs = st.executeQuery(query);
        if (rs == null)
            System.out.println("\n no rows ");
        else
            System.out.println("Rows present ");
        rs.next();

        Double start = Double.parseDouble(rs.getString(1));
        Double end = Double.parseDouble(rs.getString(2));
        Double period = 13.0;
        Double growth = Math.pow((end / start), (1 / period)) - 1;
        System.out.println("growth percentage =" + growth);
        rs.close();
        String query2 = "select [2011],[2012] from country where CountryName='" + a + "' AND SeriesName='" + b
                + "'";
        rs = st.executeQuery(query2);
        rs.next();
        series.add(2011, Double.parseDouble(rs.getString(1)));
        Double second = Double.parseDouble(rs.getString(2));
        series.add(2012, second);

        Double growthvalue = second + (second * growth);

        series.add(2013, growthvalue);
        for (int i = 2014; i <= 2016; i++) {
            System.out.println("actual growth value = " + growthvalue);
            series.add((i++), (growthvalue + growthvalue * growth));
            growthvalue = growthvalue + growthvalue * growth;
        }
        rs.close();
        dataset.addSeries(series);
        DecimalFormat format_2Places = new DecimalFormat("0.00");
        growth = growth * 100;
        growth = Double.valueOf(format_2Places.format(growth));
        JFreeChart chart = ChartFactory.createXYLineChart(
                "Energy forecasting for " + a + " based on " + b + " with growth value estimated at " + growth
                        + "% ",
                "Year", "Energy consumed in millions", dataset, PlotOrientation.VERTICAL, true, true, false);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        chart.setBackgroundPaint(Color.white);
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.black);
        plot.setRangeGridlinePaint(Color.black);

        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, false);
        plot.setRenderer(renderer);
        // To insert colored Pie Chart into the PDF file using
        // iText now   
        if (c.equals("View Graph in Browser")) {
            ChartUtilities.writeChartAsPNG(bos, chart, 700, 500);
            response.setContentType("image/png");
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            out.write(bos.toByteArray());
            out.flush();
            out.close();
        }

        else {
            int width = 640; /* Width of our chart */
            int height = 480; /* Height of our chart */
            Document PieChart = new Document(new com.itextpdf.text.Rectangle(width, height));
            java.util.Date date = new java.util.Date();
            String chartname = "My_Colored_Chart" + date.getTime() + ".pdf";
            PdfWriter writer = PdfWriter.getInstance(PieChart, new FileOutputStream(chartname));
            PieChart.open();

            PieChart.addTitle("Pie-Chart");
            PieChart.addAuthor("MUurugappan");

            PdfContentByte Add_Chart_Content = writer.getDirectContent();
            PdfTemplate template_Chart_Holder = Add_Chart_Content.createTemplate(width, height);
            Graphics2D Graphics_Chart = template_Chart_Holder.createGraphics(width, height,
                    new DefaultFontMapper());
            Rectangle2D Chart_Region = new Rectangle2D.Double(0, 0, 540, 380);
            chart.draw(Graphics_Chart, Chart_Region);
            Graphics_Chart.dispose();
            Add_Chart_Content.addTemplate(template_Chart_Holder, 0, 0);
            PieChart.close();

            PdfReader reader = new PdfReader(chartname);
            PdfStamper stamper = null;
            try {
                stamper = new PdfStamper(reader, bos);
            } catch (DocumentException e) {
                e.printStackTrace();
            }
            try {
                stamper.close();
            } catch (DocumentException e) {

                e.printStackTrace();
            }

            // set response headers to view PDF
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            response.setContentType("application/pdf");
            response.setContentLength(bos.size());

            OutputStream os = response.getOutputStream();
            bos.writeTo(os);
            os.flush();
            os.close();
        }
    }

    catch (Exception i) {
        i.printStackTrace();
    }

}

From source file:osh.comdriver.simulation.cruisecontrol.AbstractDrawer.java

/**
 * Creates a chart./*from  www . j  ava  2  s.  c o m*/
 *
 * @param dataset1  a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset, long lastentry) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title
            "time", // x-axis label
            "temperature", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis1 = new NumberAxis(getAxisName());
    axis1.setAutoRangeIncludesZero(isIncludeZero());
    plot.setRangeAxis(0, axis1);

    plot.setDataset(0, dataset);
    plot.mapDatasetToRangeAxis(1, 0);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    r1.setSeriesPaint(0, Color.BLUE);
    r1.setSeriesPaint(1, Color.RED);
    r1.setSeriesPaint(2, Color.GREEN);

    //plot.setDomainAxis(new NumberAxis("time"));
    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = getRangeBegin(lastentry);
    long end = getRangeEnd(lastentry);

    plot.getDomainAxis().setRange(begin, end);

    return chart;
}

From source file:com.googlecode.logVisualizer.chart.LineChartBuilder.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();

    double lastXValue = 0;
    if (dataset.getSeriesCount() > 0)
        lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1);

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setNoDataMessage("No data available");
    if (dataset.getSeriesCount() > 0)
        ((NumberAxis) plot.getDomainAxis()).setUpperBound(lastXValue);
    ((NumberAxis) plot.getRangeAxis()).setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesStroke(i, new BasicStroke(2));
    }/*from w  ww. j  a v  a  2s  . co m*/
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);

    return chart;
}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

public ChartPanel criaGrafico() {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("MAP ENTRE AS QUERYS", // chart title  
            "QUERY", // x axis label  
            "MAP", // y axis label  
            createDataset1(), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );/*  w  ww  .  j  a  v a  2  s .c  o  m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...  
    graf.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...  
    XYPlot plot = (XYPlot) graf.getPlot();
    plot.setDataset(1, createDataset2());
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(false);

    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(1, renderer2);

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

    ChartPanel myChartPanel = new ChartPanel(graf, true);
    return myChartPanel;
}

From source file:com.itemanalysis.jmetrik.graph.irt.IrtPlotPanel.java

private void createChart(String name, String title, String xLabel, String yLabel, double minScore,
        double maxScore) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xLabel, // x axis label
            yLabel, // y axis label
            dataset, // data
            chartOrientation, // chart orientation
            showLegend, // include legend
            true, // tooltips
            false // urls
    );/*from www  . j a  v  a2  s  .  c o  m*/

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesFilled(false);
    renderer.setDrawOutlines(true);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

    plot.getDomainAxis().setRange(minScore, maxScore);

    ChartPanel panel = new ChartPanel(chart);
    panel.getPopupMenu().addSeparator();
    panel.setPreferredSize(new Dimension(width, height));

    //        this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions

    chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
    charts.put(name, chart);

    JPanel subPanel = new JPanel();//additional panel needed to prevent gridlayout from stretching graph
    subPanel.add(panel);
    //        this.addJpgMenuItem(subPanel, panel.getPopupMenu());
    subPanel.setBackground(Color.WHITE);
    this.add(subPanel);

}

From source file:org.gumtree.vis.plot1d.Plot1D.java

private void createChart() {

    String title = null;//  ww  w .j a va  2  s  . c o  m
    String xTitle = null;
    String yTitle = null;
    if (dataset != null) {
        title = dataset.getTitle();
        xTitle = dataset.getXTitle() + (dataset.getXUnits() == null ? "" : " (" + dataset.getXUnits() + ")");
        yTitle = dataset.getYTitle() + (dataset.getYUnits() == null ? "" : " (" + dataset.getYUnits() + ")");
    } else {
        dataset = new XYErrorDataset();
    }
    chart = createXYLineChart(title, xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, false, true);
    chart.setBackgroundPaint(Color.WHITE);
    final LegendTitle legend = (LegendTitle) chart.getLegend();
    RectangleEdge legendPosition = RectangleEdge.BOTTOM;
    try {
        String legendProperty = "RectangleEdge." + System.getProperty("kuranda1D.legendPosition");
        if (RectangleEdge.BOTTOM.toString().equals(legendProperty))
            legendPosition = RectangleEdge.BOTTOM;
        else if (RectangleEdge.RIGHT.toString().equals(legendProperty))
            legendPosition = RectangleEdge.RIGHT;
        else if (RectangleEdge.LEFT.toString().equals(legendProperty))
            legendPosition = RectangleEdge.LEFT;
        else if (RectangleEdge.TOP.toString().equals(legendProperty))
            legendPosition = RectangleEdge.TOP;
    } catch (Exception e) {
        // TODO: handle exception
    }
    legend.setPosition(legendPosition);
    chart.setBorderVisible(true);
    //      ChartUtilities.applyCurrentTheme(chart);
    //      chartTheme.apply(chart);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setDomainGridlinesVisible(true);
    //        plot.setDomainCrosshairLockedOnData(true);
    //        plot.setDomainCrosshairVisible(true);
    plot.setRangeGridlinesVisible(true);
    //        plot.setRangeCrosshairLockedOnData(true);
    //        plot.setRangeCrosshairVisible(true);

    xAxis = plot.getDomainAxis();
    yAxis = plot.getRangeAxis();

    plot.setDataset(dataset);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    if (renderer instanceof XYLineAndShapeRenderer) {
        //         ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(true);
        ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(true);
    }
    //      XYErrorRenderer errorRenderer = (XYErrorRenderer) chart.getXYPlot().getRenderer();
    //      errorRenderer.setDrawXError(true);
    //        StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    //        renderer.setPlotLines(true);
    //        renderer.setBaseShapesVisible(true);

    chart.fireChartChanged();
}

From source file:Applet.EmbeddedChart.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart
            // title
            "Radial Distance,  r/\u03c3", // x axis label
            title, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

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

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    XYTitleAnnotation xyta = new XYTitleAnnotation(0.98, 0.98, chart.getLegend(), RectangleAnchor.TOP_RIGHT);
    chart.removeLegend();
    plot.addAnnotation(xyta);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    for (int i = 0; i < 2; i++) {
        renderer.setSeriesPaint(i * 6 + 0, new Color(255, 0, 0));
        renderer.setSeriesPaint(i * 6 + 1, new Color(0, 0, 255));
        renderer.setSeriesPaint(i * 6 + 2, new Color(0, 139, 0));
        renderer.setSeriesPaint(i * 6 + 3, new Color(255, 165, 0));
        renderer.setSeriesPaint(i * 6 + 4, new Color(255, 0, 255));
        renderer.setSeriesPaint(i * 6 + 5, new Color(0, 0, 0));

        renderer.setSeriesStroke(i * 6 + 0, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 1, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 50.0f, 2.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 2, new BasicStroke(1.3f, BasicStroke.JOIN_ROUND,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 30.0f, 1.0f, 1.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 3, new BasicStroke(1.3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                10.0f, new float[] { 1.0f, 3.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 4, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 2.0f, 3.0f, 4.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 5, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f, 1.0f, 20.0f, 1.0f }, 0.0f));
    }

    plot.setRenderer(renderer);

    return chart;

}

From source file:mekhq.gui.FinancesTab.java

private JFreeChart createAmountChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title
            resourceMap.getString("graphDate.text"), // x-axis label
            resourceMap.getString("graphCBills.text"), // y-axis label
            dataset);/*from www  .  j  a v a2 s .  c o  m*/

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setDefaultShapesVisible(true);
        renderer.setDefaultShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    chart.removeLegend();

    return chart;
}