Example usage for org.jfree.chart ChartPanel ChartPanel

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

Introduction

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

Prototype

public ChartPanel(JFreeChart chart) 

Source Link

Document

Constructs a panel that displays the specified chart.

Usage

From source file:ricecompression.RiceCompression.java

/**
 * @param args the command line arguments
 */// ww  w.  j av a2  s.  com
public static void main(String[] args) {
    RiceCompression rice = new RiceCompression();
    XYSeries data = new XYSeries("RICE");
    for (int i = -1023; i < 1024; i++) {
        String riceCode = rice.compress(32, i);
        data.add(i, riceCode.length());
    }
    XYSeriesCollection collection = new XYSeriesCollection(data);
    JFreeChart grafica = ChartFactory.createXYLineChart("RICE", "Nmero a codificar", "Longitud del codi Rice",
            collection, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:com.joey.software.dsp.HilbertTransform.java

public static void main(String input[]) {
    int length = 5000;

    float[] reInput = FFTSpeedTest.getSinData(length, 1000);
    float[] imInput = FFTSpeedTest.getStaticData(length, 0f);

    float[] reOutput = new float[length];
    float[] imOutput = new float[length];

    FastFourierTransform3 fft = new FastFourierTransform3(length);
    fft.fft(reInput, imInput, reOutput, imOutput);

    HilbertTransform ht = new HilbertTransform();
    getHilbert(reInput, imInput, reOutput, imOutput);

    JFreeChart inputPlot = PlotingToolkit.getPlot(new float[][] { reInput, imInput },
            new String[] { "Real", "Imaginary" }, "Input Data", "X Data", "Y Data");

    JFreeChart outputPlot = PlotingToolkit.getPlot(new float[][] { reOutput, imOutput },
            new String[] { "Real", "Imaginary" }, "Output Data", "X Data", "Y Data");

    ChartPanel p1 = new ChartPanel(inputPlot);
    ChartPanel p2 = new ChartPanel(outputPlot);

    JPanel p = new JPanel(new GridLayout(1, 2));
    p.add(p1);//from ww w .ja  v a  2  s. c  o  m
    p.add(p2);

    FrameFactroy.getFrame(p);
}

From source file:com.ohalo.cn.awt.JFreeChartTest.java

public static void main(String[] args) throws Exception {
    JFreeChartTest test = new JFreeChartTest();
    List<JFreeChart> charts = test.printHardDiskCharts();

    JPanel mainPanel = new JPanel();
    JFreeChart chart = charts.get(0);/*www .j ava2  s. c om*/
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(400, 300));
    panel.add(chartPanel, BorderLayout.CENTER);
    mainPanel.add(panel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(20, 20, 10, 10), 0, 0));

    chart = charts.get(1);
    panel = new JPanel();
    ChartPanel chartPanel2 = new ChartPanel(chart);
    chartPanel2.setPreferredSize(new Dimension(400, 300));
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel2, BorderLayout.CENTER);
    mainPanel.add(panel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));

    chart = charts.get(2);
    panel = new JPanel();
    ChartPanel chartPanel3 = new ChartPanel(chart);
    chartPanel3.setPreferredSize(new Dimension(400, 300));
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel3, BorderLayout.CENTER);
    mainPanel.add(panel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));

    chart = charts.get(3);
    panel = new JPanel();
    ChartPanel chartPanel4 = new ChartPanel(chart);
    chartPanel4.setPreferredSize(new Dimension(400, 300));
    panel.setLayout(new BorderLayout());
    panel.add(chartPanel4, BorderLayout.CENTER);

    mainPanel.add(panel, new GridBagConstraints(1, 1, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(10, 10, 20, 20), 0, 0));

    JDialog dialog = new JDialog(new JFrame(), true);
    dialog.setTitle("?");
    dialog.setSize(850, 650);
    dialog.getContentPane().add(mainPanel);
    dialog.setVisible(true);
}

From source file:edu.jhuapl.graphs.jfreechart.BarEffectsTest.java

/**
 * @param args/*w  ww .  j a va  2  s.  c om*/
 */
public static void main(String[] args) throws GraphException {
    JFreeChart chart = getSource().getChart();
    JFrame frame = new JFrame("Graph");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    ChartPanel content = new ChartPanel(chart);
    content.setPreferredSize(new Dimension(800, 500));

    frame.getContentPane().add(content);

    frame.pack();
    frame.setVisible(true);
}

From source file:ws.moor.bt.grapher.Grapher.java

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("Please specify a tab-separated values file");
        System.exit(1);//from  w  w w  .  j a  v a  2s  .c om
    }
    File file = new File(args[0]);
    final CSVMapCollector collector = new CSVMapCollector(
            new CSVSkipFilter(new CSVInputStream(new FileInputStream(file)), 0 * 1000));

    JFrame window = new JFrame("Grapher");
    window.setSize(1100, 800);
    window.setLayout(new BorderLayout());
    final ChartPanel chartPanel = new ChartPanel(null);

    List<String> possibleNames = collector.getAvailableStreams();
    Collections.sort(possibleNames);
    TreeNode root = convertToTree(possibleNames);

    final JTree tree = new JTree(root);
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            List<String> names = new ArrayList<String>();
            final TreePath[] paths = tree.getSelectionModel().getSelectionPaths();
            if (paths == null) {
                chartPanel.setChart(null);
                return;
            }
            for (TreePath path : paths) {
                Object lastPath = path.getLastPathComponent();
                if (lastPath instanceof DefaultMutableTreeNode) {
                    Object value = ((DefaultMutableTreeNode) lastPath).getUserObject();
                    if (value instanceof NodeValue) {
                        names.add(value.toString());
                    }
                }
            }
            chartPanel.setChart(createChart(collector, names.toArray(new String[names.size()])));
        }
    });
    Font font = tree.getFont();
    tree.setFont(font.deriveFont(10.0f));
    JScrollPane scrollPane = new JScrollPane(tree);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(scrollPane);
    splitPane.setRightComponent(chartPanel);
    splitPane.setDividerLocation(200);

    window.setContentPane(splitPane);
    window.setVisible(true);
}

From source file:edu.jhuapl.graphs.jfreechart.TimeSeriesEffectsTest.java

public static void main(String[] args) throws GraphException {
    JFreeChart chart = getSource().getChart();
    //      ((XYPlot)chart.getPlot()).setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    JFrame frame = new JFrame("Graph");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    ChartPanel content = new ChartPanel(chart);
    content.setPreferredSize(new Dimension(800, 500));

    frame.getContentPane().add(content);

    frame.pack();/*from   w w  w .  j a  va  2 s  . c  om*/
    frame.setVisible(true);
}

From source file:org.mili.jmibs.jfree.examples.Example5.java

/**
 * @param args//from   ww w.  j a  v a2s.  co  m
 */
public static void main(String[] args) {
    /* list with iterations. */
    List<Integer> il = new ArrayList<Integer>() {
        {
            add(100);
            add(1000);
            add(10000);
        }
    };

    /* list with object loadings. */
    List<Integer> ol = new ArrayList<Integer>() {
        {
            add(1000);
            add(10000);
        }
    };

    /* create the suite. */
    BenchmarkSuite bs = DefaultIterationObjectLoadBenchmarkSuite.create(il, ol);

    /* add some benches. */
    bs.addBenchmark(new ReplaceStringBenchmark());
    bs.addBenchmark(new ReplaceStringAppendBenchmark());
    bs.addBenchmark(new ReplaceStringAppendSingleBenchmark());

    /* execute the suite. */
    IterationObjectLoadBenchmarkSuiteResult bsr = (IterationObjectLoadBenchmarkSuiteResult) bs.execute();

    /* create a renderer. */
    BenchmarkSuiteResultRenderer<JFreeChart> bsrr = JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer
            .create();

    /* display the results. */
    ApplicationFrame af = new ApplicationFrame(bsr.getBenchmarkSuite().getName());
    ChartPanel chartPanel = new ChartPanel(bsrr.render(bsr));
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true);
    chartPanel.setPreferredSize(new Dimension(640, 480));
    af.setContentPane(chartPanel);
    af.pack();
    RefineryUtilities.centerFrameOnScreen(af);
    af.setVisible(true);
}

From source file:org.mili.jmibs.jfree.examples.Example4.java

/**
 * @param args/*from  w w w.  j a  v  a 2  s.  c  om*/
 */
public static void main(String[] args) {
    /* list with iterations. */
    List<Integer> il = new ArrayList<Integer>() {
        {
            add(100);
            add(1000);
            add(10000);
        }
    };

    /* list with object loadings. */
    List<Integer> ol = new ArrayList<Integer>() {
        {
            add(1000);
            add(10000);
        }
    };

    /* create the suite. */
    BenchmarkSuite bs = DefaultIterationObjectLoadBenchmarkSuite.create(il, ol);

    /* add some benches. */
    bs.addBenchmark(new AppendStringBufferBenchmark());
    bs.addBenchmark(new AppendStringBuilderBenchmark());
    bs.addBenchmark(new AppendStringConcatBenchmark());
    bs.addBenchmark(new AppendStringPlusBenchmark());

    /* execute the suite. */
    IterationObjectLoadBenchmarkSuiteResult bsr = (IterationObjectLoadBenchmarkSuiteResult) bs.execute();

    /* create a renderer. */
    BenchmarkSuiteResultRenderer<JFreeChart> bsrr = JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer
            .create();

    /* display the results. */
    ApplicationFrame af = new ApplicationFrame(bsr.getBenchmarkSuite().getName());
    ChartPanel chartPanel = new ChartPanel(bsrr.render(bsr));
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true);
    chartPanel.setPreferredSize(new Dimension(640, 480));
    af.setContentPane(chartPanel);
    af.pack();
    RefineryUtilities.centerFrameOnScreen(af);
    af.setVisible(true);
}

From source file:LoggerGUI.MainFrame.java

public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            /*JFrame frame = new JFrame("Charts");
                    //from  w w  w. j  a  v  a2  s.c om
            frame.setSize(700, 400);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
                */

            DataLogger demo = new DataLogger("DemoUI", 51);

            Container contentPane = demo.getContentPane();

            demo.pack();

            demo.setVisible(true);
            demo.setSize(100, 100);

            demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            demo.setVisible(true);

            XYDataset ds = createDataset();
            JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "x", "y", ds,
                    PlotOrientation.HORIZONTAL, true, true, false);

            ChartPanel cp = new ChartPanel(chart);

            //cp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            //contentPane.add(cp, BorderLayout.EAST);

            //cp.setSize(100,100);

            //RefineryUtilities.centerFrameOnScreen(demo);

            demo.pack();

        }
    });

}

From source file:org.mili.jmibs.jfree.examples.Example6.java

/**
 * @param args/*from   w w w. j a  va2s.co  m*/
 */
public static void main(String[] args) {
    /* list with iterations. */
    List<Integer> il = new ArrayList<Integer>() {
        {
            add(100);
            add(1000);
            add(10000);
        }
    };

    /* list with object loadings. */
    List<Integer> ol = new ArrayList<Integer>() {
        {
            add(10);
            add(20);
            add(30);
            add(40);
            add(50);
        }
    };

    /* create the suite. */
    BenchmarkSuite bs = DefaultIterationObjectLoadBenchmarkSuite.create(il, ol);

    /* add some benches. */
    // really slow ...
    //bs.addBenchmarkClass(FibonacciRecursiveBenchmark.class);
    bs.addBenchmark(new FibonacciEndRecursiveBenchmark());
    bs.addBenchmark(new FibonacciNonRecursiveBenchmark());
    bs.addBenchmark(new FibonacciExplicitBenchmark());

    /* execute the suite. */
    IterationObjectLoadBenchmarkSuiteResult bsr = (IterationObjectLoadBenchmarkSuiteResult) bs.execute();

    /* create a renderer. */
    BenchmarkSuiteResultRenderer<JFreeChart> bsrr = JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer
            .create();

    /* display the results. */
    ApplicationFrame af = new ApplicationFrame(bsr.getBenchmarkSuite().getName());
    ChartPanel chartPanel = new ChartPanel(bsrr.render(bsr));
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseZoomable(true);
    chartPanel.setPreferredSize(new Dimension(640, 480));
    af.setContentPane(chartPanel);
    af.pack();
    RefineryUtilities.centerFrameOnScreen(af);
    af.setVisible(true);
}