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(Plot plot) 

Source Link

Document

Creates a new chart based on the supplied plot.

Usage

From source file:ch.zhaw.ias.dito.ui.util.BlockPlotPanel.java

public BlockPlotPanel(Matrix m, double lowerBound, double upperBound) {
    super(new BorderLayout());
    NumberAxis xAxis = new NumberAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(1.0);// w  ww . j a va2  s  .  c om
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(1.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            XYZDataset xyzDataset = (XYZDataset) dataset;
            double x = xyzDataset.getXValue(series, item);
            double y = xyzDataset.getYValue(series, item);
            double z = xyzDataset.getZValue(series, item);
            return ("X=" + x + ", Y=" + y + ", Z=" + z);
        }
    });
    PaintScale scale = new ColorPaintScale(lowerBound, upperBound);
    renderer.setPaintScale(scale);
    ValueAxis axis = new NumberAxis();
    axis.setLowerBound(scale.getLowerBound());
    axis.setUpperBound(scale.getUpperBound());
    PaintScaleLegend legend = new PaintScaleLegend(scale, axis);
    legend.setMargin(new RectangleInsets(10, 10, 10, 10));
    legend.setPosition(RectangleEdge.RIGHT);

    MatrixXYDataset dataset = new MatrixXYDataset(m);
    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    chart = new JFreeChart(plot);
    chart.removeLegend();
    chart.addSubtitle(legend);
    chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDisplayToolTips(true);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:org.shredzone.bullshitcharts.servlet.ChartServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String pathInfo = req.getPathInfo();
    PlotGenerator generator = null;/*from w w w.java  2s. com*/
    if ("/pie.png".equals(pathInfo)) {
        generator = new ChoicePieGenerator();
    } else if ("/agree.png".equals(pathInfo)) {
        generator = new AgreementPieGenerator();
    } else if ("/line.png".equals(pathInfo)) {
        generator = new LineChartGenerator();
    } else if ("/bar.png".equals(pathInfo)) {
        generator = new BarChartGenerator();
    } else {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    generator.configure(req);

    Plot plot = generator.generate();

    // Generate the chart
    JFreeChart chart = new JFreeChart(plot);
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    chart.setBorderVisible(false);
    chart.removeLegend();

    String title = req.getParameter("title");
    if (title != null) {
        chart.setTitle(title);
    }

    // Write the chart to a byte array. It is small enough so it won't load the
    // server's memory too much.
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        ChartUtilities.writeChartAsPNG(baos, chart, IMAGE_WIDTH, IMAGE_HEIGHT);
        byte[] data = baos.toByteArray();

        // Stream the chart
        resp.setContentType("image/png");
        resp.setContentLength(data.length);
        resp.setHeader("Cache-Control", "no-cache, must-revalidate");
        resp.setHeader("Expires", "Sat, 01 Jan 2000 00:00:00 GMT");
        resp.getOutputStream().write(data);
    }
}

From source file:org.geotools.renderer.chart.GeometryRendererTest.java

void showChart(XYPlot plot) throws Exception {
    JFreeChart chart = new JFreeChart(plot);
    chart.setAntiAlias(true);//w  w  w .j  ava 2  s  . c om
    ChartPanel panel = new ChartPanel(chart, true);

    final String headless = System.getProperty("java.awt.headless", "false");
    if (!headless.equalsIgnoreCase("true") && TestData.isInteractiveTest()) {
        try {
            JFrame frame = new JFrame(getName());
            frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    e.getWindow().dispose();
                }
            });
            frame.setContentPane(panel);
            frame.setSize(new Dimension(500, 500));
            frame.setVisible(true);

            Thread.sleep(5000);
            frame.dispose();
        } catch (HeadlessException exception) {
            // The test is running on a machine without X11 display. Ignore.
            return;
        }
    }
}

From source file:AsymptoticFreedom.AppletAF.java

@Override
public void init() {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     *//*from w  w  w  .j a  v  a  2 s  . c  om*/
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(AppletAF.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(AppletAF.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(AppletAF.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(AppletAF.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>
    //</editor-fold>

    /* Create and display the applet */
    try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                chart = new JFreeChart(new XYPlot());
                initComponents();
            }
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:RutherfordScattering.RutherfordScattering.java

/**
 * Initializes the applet RutherfordScattering
 *///  w  ww  .j av a2 s  . com
@Override
public void init() {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(RutherfordScattering.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(RutherfordScattering.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(RutherfordScattering.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(RutherfordScattering.class.getName())
                .log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the applet */
    try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                initComponents();
                chart = new JFreeChart(new XYPlot());
            }
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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

/**
 * Creates a chart./*from w  w w  . j a  va  2 s  . c  o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final ValueDataset dataset) {

    final CompassPlot plot = new CompassPlot(dataset);
    plot.setSeriesNeedle(7);
    plot.setSeriesPaint(0, Color.red);
    plot.setSeriesOutlinePaint(0, Color.red);
    final JFreeChart chart = new JFreeChart(plot);
    return chart;

}

From source file:netplot.DialPlotPanel.java

public void init() {
    finalize();/*from   w  ww.ja  v  a 2  s . c  o m*/
    this.dataset1 = new DefaultValueDataset(10.0);
    this.dataset2 = new DefaultValueDataset(50.0);

    // get data for diagrams
    plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    plot.setDataset(0, this.dataset1);
    plot.setDataset(1, this.dataset2);
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.darkGray);
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(db);

    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    chart = new JFreeChart(plot);
    ChartPanel cp1 = new ChartPanel(chart);
    cp1.setPreferredSize(new Dimension(400, 400));

    add(cp1);
}

From source file:Panels.FinanzPanel.java

public void callDb() {

    try {// w w w .j  av a2 s.  co m
        st = this.dc.getOracleConnector().dbcon.createStatement();
        result = st.executeQuery("select * from finanzplan where IDFinPlan=" + name + "");
        while (result.next()) {
            System.out.println("Test:" + result.getInt("geplant"));
            dataset.setValue("GEPLANT", new Double(result.getFloat("GEPLANT")));
            dataset.setValue("VORHANDEN", new Double(result.getFloat("VORHANDEN")));

        }

        plot = new PiePlot(dataset);
        chart1 = new JFreeChart(plot);
        chartPanel1 = new ChartPanel(chart1);
        chartPanel1.setMouseWheelEnabled(true);
        this.setLayout(new java.awt.BorderLayout());
        this.add(chartPanel1, BorderLayout.CENTER);
        this.validate();
    } catch (SQLException ex) {
        Logger.getLogger(MitarbeiterPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelDetailMass.java

public boolean loadData() {
    super.loadData();

    // Tabelle // w w w  .  jav a2 s.com
    MassenTableModel m = new MassenTableModel(app.getXmlClient());
    m.load(objektNode, t, s);
    panelMass.setModel(m);
    panelMass.setObjektNode(objektNode);

    // Grafik
    XYDataset xyDataset = new TableModelXYDataset(m, true);
    StatusItemRenderer statusRenderer = new StatusItemRenderer(m, 2);

    NumberAxis rangeAxis = new NumberAxis(
            ChartUtils.getNumberAxisLabel(app.getXmlClient(), objektNode.getId()));
    DateAxis domainAxis = new DateAxis("Time");
    Plot plot = new StatusXYPlot(xyDataset, domainAxis, rangeAxis, statusRenderer);

    JFreeChart f = new JFreeChart(plot);
    StandardLegend l = new StandardLegend(f);

    panelChart.setChart(f);
    panelChart.setLegend(l);

    // Link 
    m.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            panelChart.repaint();
        }

    });

    return true;
}

From source file:soap.ui.stats.OverLaidBarChartFactory.java

public static JFreeChart createDualBarAndLineDiagram(String title, String categoryAxisLabel,
        String valueAxisLabel, CategoryDataset barDiagramDataset, LinkedList lineDiagramDatasets) {
    CategoryPlot plot = new CategoryPlot();
    int inc = 0;//  w ww.j  a v  a  2 s.  c  om
    BarRenderer barRenderer = null;
    if (barDiagramDataset != null) {
        plot.setDataset(barDiagramDataset);
        barRenderer = new BarRenderer3D();
        barRenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        plot.setRenderer(barRenderer);
        inc = 1;
        plot.setDomainAxis(new CategoryAxis3D(categoryAxisLabel));
        plot.setRangeAxis(new NumberAxis3D(valueAxisLabel));
    } else {
        plot.setDomainAxis(new CategoryAxis(categoryAxisLabel));
        plot.setRangeAxis(new NumberAxis(valueAxisLabel));
    }
    plot.mapDatasetToRangeAxis(0, 0);

    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    CategoryItemRenderer renderers[] = new LineAndShapeRenderer[lineDiagramDatasets.size()];

    for (int i = 0; i < lineDiagramDatasets.size(); i++) {
        CategoryDataset lineDiagramDataset = (CategoryDataset) lineDiagramDatasets.get(i);
        plot.setDataset(i + inc, lineDiagramDataset);
        plot.mapDatasetToRangeAxis(i + inc, 0);
        if (barDiagramDataset != null && i < barDiagramDataset.getRowCount()) {
            renderers[i] = new LineAndShapeRendererMapToBar(barRenderer, i);
        } else {
            renderers[i] = new LineAndShapeRenderer();
        }
        renderers[i].setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderers[i].setSeriesStroke(0, new BasicStroke(1.5f));
        renderers[i].setSeriesStroke(1, new BasicStroke(1.5f));
        plot.setRenderer(i + inc, renderers[i]);
    }

    CategoryDataset dataset;
    if (lineDiagramDatasets.size() > 0)
        dataset = (CategoryDataset) lineDiagramDatasets.get(0);
    else
        dataset = barDiagramDataset;
    for (int i = 0; i < dataset.getColumnCount(); i++)
        plot.getDomainAxis().addCategoryLabelToolTip(dataset.getColumnKey(i), (String) dataset.getColumnKey(i));

    plot.setRangeGridlinePaint(Color.black);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(title);
    chart.setLegend(new StandardLegend());

    return chart;
}