Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart JFreeChart.

Prototype

public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

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

/**
 * The starting point for the demo.//from www  . jav a  2  s .  co  m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a chart
    final DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("One", new Double(43.2));
    data.setValue("Two", new Double(10.0));
    data.setValue("Three", new Double(27.5));
    data.setValue("Four", new Double(17.5));
    data.setValue("Five", new Double(11.0));
    data.setValue("Six", new Double(19.4));

    JFreeChart chart = null;
    final boolean drilldown = true;

    // create the chart...
    if (drilldown) {
        final PiePlot plot = new PiePlot(data);
        //          plot.setInsets(new Insets(0, 5, 5, 5));
        plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
        plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp"));
        chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
                data, // data
                true, // include legend
                true, false);
    }
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("piechart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("piechart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo 2</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"piechart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }

}

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

/**
 * Starting point for the demo.//from  www  . ja  va  2 s . c  om
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a chart
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    JFreeChart chart = null;
    final boolean drilldown = true;

    if (drilldown) {
        final CategoryAxis3D categoryAxis = new CategoryAxis3D("Category");
        final ValueAxis valueAxis = new NumberAxis3D("Value");
        final BarRenderer3D renderer = new BarRenderer3D();
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp"));
        final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        chart = ChartFactory.createBarChart3D("Bar Chart", // chart title
                "Category", // domain axis label
                "Value", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, false);
    }
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("barchart101.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("barchart101.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"barchart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }

}

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

/**
 * Starting point for the demo.//from w  w  w  .j a  v a  2 s .c  o  m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a chart
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    JFreeChart chart = null;
    final boolean drilldown = true;

    if (drilldown) {
        final CategoryAxis categoryAxis = new CategoryAxis("Category");
        final ValueAxis valueAxis = new NumberAxis("Value");
        final BarRenderer renderer = new BarRenderer();
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp"));
        final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        chart = ChartFactory.createBarChart("Vertical Bar Chart", // chart title
                "Category", // domain axis label
                "Value", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, false);
    }
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("barchart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("barchart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"barchart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }

}

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

/**
 * Starting point for the demo./*from   w  w  w.j a v  a  2s  .  c o  m*/
 *
 * @param args  ignored.
 *
 * @throws ParseException if there is a problem parsing dates.
 */
public static void main(final String[] args) throws ParseException {

    //  Create a sample dataset
    final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    final XYSeries dataSeries = new XYSeries("Curve data");
    final ArrayList toolTips = new ArrayList();
    dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22);
    toolTips.add("1D - 5.22");
    dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18);
    toolTips.add("2D - 5.18");
    dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23);
    toolTips.add("3D - 5.23");
    dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15);
    toolTips.add("4D - 5.15");
    dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22);
    toolTips.add("5D - 5.22");
    dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25);
    toolTips.add("6D - 5.25");
    dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31);
    toolTips.add("7D - 5.31");
    dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36);
    toolTips.add("8D - 5.36");
    final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
    final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator();
    ttg.addToolTipSeries(toolTips);

    //  Create the chart
    final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp");
    final ValueAxis timeAxis = new DateAxis("");
    final NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null);
    final StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
            StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg);
    sxyir.setShapesFilled(true);
    plot.setRenderer(sxyir);
    final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("xychart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("xychart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"xychart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return;
}

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

public static JPanel createDemoPanel() {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    XYPlot xyplot = new XYPlot(createSampleData(), numberaxis, numberaxis1, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("XYSplineRenderer", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    return chartpanel;
}

From source file:org.gwaspi.gui.TestReports.java

public static File createCombinedPNGFromAssocUnadjLogPvsPos(File plinkReport, File outputFile,
        Set<String> redMarkers, int width, int height) throws FileNotFoundException, IOException {
    // Generating XY scatter plot with loaded data
    CombinedRangeXYPlot combinedPlot = org.gwaspi.reports.PlinkReportLoaderCombined
            .loadAssocUnadjLogPvsPos(plinkReport, redMarkers);

    JFreeChart chart = new JFreeChart("P value x Chr position", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot,
            true);/*from ww  w .ja v  a 2s . com*/

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, width, height);
    } catch (IOException ex) {
        log.error("Problem occurred creating chart", ex);
    }

    return null;
}

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

private static JFreeChart createChart(ValueDataset valuedataset) {
    MeterPlot meterplot = new MeterPlot(valuedataset);
    meterplot.setRange(new Range(0.0D, 60D));
    meterplot.addInterval(new MeterInterval("Normal", new Range(0.0D, 35D), Color.lightGray,
            new BasicStroke(2.0F), new Color(0, 255, 0, 64)));
    meterplot.addInterval(new MeterInterval("Warning", new Range(35D, 50D), Color.lightGray,
            new BasicStroke(2.0F), new Color(255, 255, 0, 64)));
    meterplot.addInterval(new MeterInterval("Critical", new Range(50D, 60D), Color.lightGray,
            new BasicStroke(2.0F), new Color(255, 0, 0, 128)));
    meterplot.setNeedlePaint(Color.darkGray);
    meterplot.setDialBackgroundPaint(Color.white);
    meterplot.setDialOutlinePaint(Color.gray);
    meterplot.setDialShape(DialShape.CHORD);
    meterplot.setMeterAngle(260);/*from  w w w.  ja va 2s .  c o m*/
    meterplot.setTickLabelsVisible(true);
    meterplot.setTickLabelFont(new Font("Dialog", 1, 10));
    meterplot.setTickLabelPaint(Color.darkGray);
    meterplot.setTickSize(5D);
    meterplot.setTickPaint(Color.lightGray);
    meterplot.setValuePaint(Color.black);
    meterplot.setValueFont(new Font("Dialog", 1, 14));
    JFreeChart jfreechart = new JFreeChart("Meter Chart 1", JFreeChart.DEFAULT_TITLE_FONT, meterplot, true);
    return jfreechart;
}

From source file:Componentes.TermometroMax.java

@Override
public void pintar(javax.swing.JPanel p, int pos) {
    p.removeAll();//from   ww w. j a  v a2s.co  m
    DefaultValueDataset data = new DefaultValueDataset(new Double(ventana.getGraphdata().getTmax()));

    ThermometerPlot plot = new ThermometerPlot(data);
    chart = new JFreeChart("Temperatura Maxima, \nMES: " + Calculos.get_mes(ventana.getMonthdata().getdata()), // chart title
            JFreeChart.DEFAULT_TITLE_FONT, plot, // plot
            false);

    Color Darkorange = new Color(255, 140, 0);
    Color Crimson = new Color(220, 20, 60);
    Color Aquamarine = new Color(127, 255, 212);
    Color Darkslategray = new Color(47, 79, 79);

    plot.setMercuryPaint(Aquamarine);
    plot.setSubrange(NORMAL, 0, 10);
    plot.setSubrange(WARNING, 10.1, 20);
    plot.setSubrange(CRITICAL, 20.1, 50);
    plot.setSubrangePaint(NORMAL, Aquamarine);
    plot.setSubrangePaint(WARNING, Darkorange);
    plot.setSubrangePaint(CRITICAL, Crimson);

    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Darkslategray);

    plot.setDisplayRange(5, Calculos.get_min(datos.getTmax()), Calculos.get_max(datos.getTmax()));
    plot.setRange(Calculos.get_min(datos.getTmax()), Calculos.get_max(datos.getTmax()));

    panel = new ChartPanel(chart);
    panel.setBounds(5, 5, 300, 300);
    panel.repaint();
    p.add(panel);
    // jPanel1.repaint();
    p.updateUI();
    // aoIndex=aoAux;
    ///aoAux = 0;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    SpiderWebPlot plot = new SpiderWebPlot(categorydataset);
    plot.setStartAngle(54D);// www .ja v  a 2s . c om
    plot.setInteriorGap(0.40000000000000002D);
    plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    JFreeChart chart = new JFreeChart("Spider Web Chart Demo 1", TextTitle.DEFAULT_FONT, plot, false);
    LegendTitle legendtitle = new LegendTitle(plot);
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legendtitle);
    return chart;
}

From source file:UserInterface.FarmerRole.HumidityGraph.java

public HumidityGraph(double value, String type) {

    data = new DefaultValueDataset(value);
    final JFrame frame = new JFrame();
    meterPlot = new MeterPlot(data);
    frame.getContentPane().setLayout(new BorderLayout(5, 5));
    frame.setDefaultCloseOperation(3);/*from w ww. ja v  a  2 s  . com*/
    frame.setTitle("Inventory Humidity");
    meterChart = new JFreeChart("Humidity Chart", JFreeChart.DEFAULT_TITLE_FONT, this.meterPlot, false);
    panelMeter = new ChartPanel(this.meterChart);
    frame.getContentPane().add(panelMeter, BorderLayout.CENTER);
    frame.setSize(700, 400);
    final Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);

}