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

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

Introduction

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

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:ac.kaist.ccs.presentation.CCSHubSelectionCoverage.java

/**
 * Creates a chart./*from w w w  .java2 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(title, // chart title
            "Number of Hubs", // x axis label
            "Percent of CO2 emission source node coverage (%)", // 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);

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

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    //final NumberAxis xAxis = (NumberAxis) plot.getRangeAxis();
    //xAxis.setTickUnit(new NumberTickUnit(10));
    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);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //renderer.setSeriesLinesVisible(0, false);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:imc.graficaIMC.java

public graficaIMC() {
    TimeSeries s1 = new TimeSeries("REGISTRO DE IMC ");
    datos.removeAllSeries();/*from ww w . j a  v a2 s .co m*/
    //sxy.add(x[0], y[0]);
    pesos = new double[imc.imc.length];
    fecha = new String[imc.fecha.length];
    pesos = imc.imc;
    fecha = imc.fecha;
    ///////////////77

    Date fechaDate = null;

    int n = pesos.length;
    Calendar calendar = Calendar.getInstance();

    for (int i = 0; i < n; i++) {
        // JOptionPane.showMessageDialog(null, "fecha tio:"+fecha[i]);
        try {
            fechaDate = formato.parse(fecha[i]);
            calendar.setTime(fechaDate);
        } catch (ParseException ex) {

        }
        //  JOptionPane.showMessageDialog(null, calendar.get(Calendar.DAY_OF_MONTH)+" "+calendar.get(Calendar.MONTH)+1+" "+ calendar.get(Calendar.YEAR));
        s1.add(new Day(calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.YEAR)), pesos[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datos.addSeries(s1);
    grafica = ChartFactory.createTimeSeriesChart("Progreso de MCM", "Fecha", "IMC", datos, true, true, false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.getPlot();
    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);

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

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

}

From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java

private static JFreeChart createBubbleChart(XYZDataset dataset) {
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    //        A renderer that draws a circle at each data point with a diameter that is
    //        determined by the z-value in the dataset (the renderer requires the dataset
    //        to be an instance of {@link XYZDataset}.
    XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    }//from  w w  w .  ja v a 2s.  c o  m
    if (urls) {
        renderer.setURLGenerator(new StandardXYZURLGenerator());
    }
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart("Bubble Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

    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);

    return chart;
}

From source file:dpnm.netmsuite.plc.manager.frontend.graph.TimeSeriesChartDemo1.java

/**
 * Creates a chart.//from   w w  w.jav  a2 s .c om
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = null;
    if (this.graphType == 1) {
        chart = ChartFactory.createTimeSeriesChart(title, // title
                "Minute", // x-axis label
                "Packets/sec", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false // generate URLs?
        );
    } else if (this.graphType == 2) {
        chart = ChartFactory.createTimeSeriesChart(title, // title
                "Minute", // x-axis label
                "Bytes/sec", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false // generate URLs?
        );
    } else {
        chart = ChartFactory.createTimeSeriesChart(title, // title
                "Minute", // x-axis label
                "KBps", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false // generate URLs?
        );
    }

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));

    return chart;

}

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

public ChartPanel interpolado(int index) {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("Interpolado", // chart title  
            "Recall", // x axis label  
            "Precision", // y axis label  
            createDatasetInterpoled(index), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );//from  w  w  w  .jav  a2  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.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:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

public ChartPanel media11() {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("Media 11 Pontos", // chart title  
            "Recall", // x axis label  
            "Precision", // y axis label  
            createDatasetOnze(), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );/*from  w ww.ja 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.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:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

public ChartPanel media11(int index) {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("Media 11 pontos", // chart title  
            "Recall", // x axis label  
            "Precision", // y axis label  
            createDatasetOnze(index), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );//from   ww w .  j  a v  a2s .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.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:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

/***************************************** INDIVIDUAIS **************************************************/

public ChartPanel precisionrecall(int index) {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("Precision Recall", // chart title  
            "Recall", // x axis label  
            "Precision", // y axis label  
            createDatasetprecision(index), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );/*w w  w. j a va 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.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.swing.GraphPanel.java

public void setLineChart(String title, String subtitle, String xlabel, String ylabel) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    chart = ChartFactory.createXYLineChart(title, // chart title
            xlabel, // x axis label
            ylabel, // y axis label
            dataset, // data
            chartOrientation, showLegend, // include legend
            true, // tooltips
            false // urls
    );//w  w  w .  ja va 2s. co m

    if (showLegend) {
        LegendTitle chartTitle = chart.getLegend();
        chartTitle.setPosition(legendPosition);
    }

    if (subtitle != null && !"".equals(subtitle)) {
        TextTitle subtitle1 = new TextTitle(subtitle);
        chart.addSubtitle(subtitle1);
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

    //can use this code to modify charts for book. DO NOT USE FOR NORMAL FUNCTIONING
    //        NumberAxis yaxis = (NumberAxis)plot.getRangeAxis();
    //        yaxis.setTickUnit(new NumberTickUnit(.1));

    ChartPanel panel = new ChartPanel(chart);
    panel.getPopupMenu().addSeparator();
    this.addJpgMenuItem(this, panel.getPopupMenu());
    //        this.addEPSMenuItem(this, panel.getPopupMenu());//remove this line for public release versions
    panel.setPreferredSize(new Dimension(width, height));

    chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
    this.setBackground(Color.WHITE);
    this.add(panel);

}

From source file:Servlet3.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*w  w  w .  jav  a 2 s .  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();
    }

}