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:org.jfree.chart.demo.MouseListenerDemo2.java

public MouseListenerDemo2(String s) {
    super(s);/*from   www.jav  a2 s  . c  om*/
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    defaultcategorydataset.addValue(1.0D, "S1", "C1");
    defaultcategorydataset.addValue(4D, "S1", "C2");
    defaultcategorydataset.addValue(3D, "S1", "C3");
    defaultcategorydataset.addValue(5D, "S1", "C4");
    defaultcategorydataset.addValue(5D, "S1", "C5");
    defaultcategorydataset.addValue(6D, "S1", "C6");
    defaultcategorydataset.addValue(7D, "S1", "C7");
    defaultcategorydataset.addValue(8D, "S1", "C8");
    defaultcategorydataset.addValue(5D, "S2", "C1");
    defaultcategorydataset.addValue(7D, "S2", "C2");
    defaultcategorydataset.addValue(6D, "S2", "C3");
    defaultcategorydataset.addValue(8D, "S2", "C4");
    defaultcategorydataset.addValue(4D, "S2", "C5");
    defaultcategorydataset.addValue(4D, "S2", "C6");
    defaultcategorydataset.addValue(3D, "S2", "C7");
    defaultcategorydataset.addValue(1.0D, "S2", "C8");
    defaultcategorydataset.addValue(4D, "S3", "C1");
    defaultcategorydataset.addValue(3D, "S3", "C2");
    defaultcategorydataset.addValue(2D, "S3", "C3");
    defaultcategorydataset.addValue(3D, "S3", "C4");
    defaultcategorydataset.addValue(6D, "S3", "C5");
    defaultcategorydataset.addValue(3D, "S3", "C6");
    defaultcategorydataset.addValue(4D, "S3", "C7");
    defaultcategorydataset.addValue(3D, "S3", "C8");
    org.jfree.chart.JFreeChart jfreechart = ChartFactory.createBarChart("Test", "Category", "Value",
            defaultcategorydataset, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.addChartMouseListener(this);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartpanel);
}

From source file:org.ensor.robots.apps.pidcallibrator.MainPanel.java

/**
 * Creates new form MainPanel//  ww w. j  av  a 2s.  c  om
 */
public MainPanel() {
    initComponents();

    XYSeriesCollection collection = new XYSeriesCollection();

    XYSeries setPoints = new XYSeries("Set Points");
    setPoints.add(10, 0);
    setPoints.add(20, 10);
    setPoints.add(30, 5);
    setPoints.add(40, 20);
    collection.addSeries(setPoints);

    XYSeries actualPoints = new XYSeries("Actual Points");
    actualPoints.add(5, 0);
    actualPoints.add(15, 5);
    actualPoints.add(40, 50);
    collection.addSeries(actualPoints);

    JFreeChart scatterPlot = ChartFactory.createScatterPlot("Angle PID tracking", "Time", "Angle", collection);

    ChartPanel cp = new ChartPanel(scatterPlot);
    mChart.setLayout(new BorderLayout());
    mChart.add(cp, BorderLayout.CENTER);
    mChart.validate();
    cp.setSize(mChart.getSize());

}

From source file:eu.choreos.vv.chart.XYChart.java

public XYChart(String applicationTitle, String chartTitle, List<PlotData> reports, String xLabel,
        String yLabel) {//from   www.  j  a  v  a 2s . co  m
    super(applicationTitle);

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();

    for (PlotData report : reports) {
        createDataset(dataset, (LineData) report);
    }
    // based on the dataset we create the chart
    JFreeChart chart = createChart(dataset, chartTitle, xLabel, yLabel);
    // we put the chart into a panel
    ChartPanel chartPanel = new ChartPanel(chart);
    // default size
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    // add it to our application
    setContentPane(chartPanel);

}

From source file:net.imglib2.script.analysis.BarChart.java

public BarChart(final Collection<? extends Number> data, final String title, final String xLabel,
        final String yLabel) {
    super(title);
    this.chart = createChart(data, title, xLabel, yLabel);
    this.getContentPane().add(new ChartPanel(chart));
    this.pack();//  ww  w . j av a  2 s.  c  o m
    this.setVisible(true);
}

From source file:org.samjoey.graphing.GraphUtility.java

/**
 *
 * @param games the games to graph/*from  w ww  . j  av a 2s.c o  m*/
 * @param key the variable to create the graph with
 * @param start if index, the index at which to start, else the percent in
 * the game at which to start
 * @param stop if index, the index at which to end, else the percent in the
 * game at which to end
 * @param index
 * @return
 */
public static ChartPanel getCustomGraph(Game[] games, String key, double start, double stop, boolean index) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (Game game : games) {
        ArrayList<Double> data = game.getVar(key);
        int begin;
        int end;
        if (index) {
            begin = (int) start;
            end = (int) stop;
        } else {
            begin = (int) (data.size() / start);
            end = (int) (data.size() / stop);
        }
        XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId());
        dataset.addSeries(series);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer rend = plot.getRenderer();
    for (int i = 0; i < games.length; i++) {
        Game g = games[i];
        if (g.getWinner() == 1) {
            rend.setSeriesPaint(i, Color.RED);
        }
        if (g.getWinner() == 2) {
            rend.setSeriesPaint(i, Color.BLACK);
        }
        if (g.getWinner() == 0) {
            rend.setSeriesPaint(i, Color.PINK);
        }
    }
    ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

From source file:org.sunzoft.sunstock.StockMain.java

protected void initGUI() {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1024, 600);//from   w w w . j a  va 2s  . c o m
    frame.setLocationRelativeTo(null);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            // 
            Container contentPane = frame.getContentPane();
            contentPane.setLayout(new BorderLayout(0, 0));

            JFreeChart chart = createChart();
            // 6:chartPanel        
            chartPanel = new ChartPanel(chart);
            chartPanel.setMouseZoomable(true);
            contentPane.add(chartPanel, BorderLayout.CENTER);

            JPanel pCtrl = new JPanel();
            if (profits.size() > 0) {
                startInput.setText(profits.get(0).date);
                endInput.setText(profits.get(profits.size() - 1).date);
            } else {
                startInput.setText("20100101");
                endInput.setText("20100101");
            }
            pCtrl.add(new JLabel(""));
            pCtrl.add(startInput);
            pCtrl.add(new JLabel(""));
            pCtrl.add(endInput);
            JButton confirm = new JButton("");
            confirm.addActionListener(StockMain.this);
            pCtrl.add(confirm);
            contentPane.add(pCtrl, BorderLayout.NORTH);

            JPanel pStatus = new JPanel();
            statusLabel = new JLabel(getStatusText());
            pStatus.add(statusLabel);
            contentPane.add(pStatus, BorderLayout.SOUTH);

            frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
            frame.setVisible(true);
            //dataSource.close();
        }
    });
}

From source file:imageviewer.tools.HistogramTool.java

public HistogramTool() {

    cp = new ChartPanel(null);
    cp.setOpaque(false);//from  www.  j  a va2 s.c  o  m
    cp.setPreferredSize(new Dimension(500, 350));
    cp.setBorder(new EmptyBorder(5, 0, 0, 0));
}

From source file:compecon.dashboard.panel.MoneyPanel.java

protected ChartPanel createCreditUtilizationRatePanel() {
    TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

    for (Currency currency : Currency.values())
        timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
                .getNationalEconomyModel(currency).creditUtilizationRateModel.getTimeSeries());

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Credit Utilization Rate", "Date",
            "Credit Utilization Rate", timeSeriesCollection, true, true, false);
    configureChart(chart);/*from  www .  j  a  va2s  .com*/
    return new ChartPanel(chart);
}

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

/**
 * Creates a new demo instance.//from ww  w.  j  a  v a2  s .c o m
 *
 * @param title  the frame title.
 */
public PieChartDemo5(final String title) {
    super(title);
    final PieDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:graph.MySensorPanel.java

/**
 * Creates a new self-contained demo panel.
 *//*from  w ww  . ja v a 2 s .  c  om*/
public MySensorPanel(String header_str) {
    //super(new BorderLayout());
    this.series1 = new TimeSeries("Temperature");
    this.series2 = new TimeSeries("Humidity");
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(header_str, "Time", "C", dataset1, true, true,
            false);

    /*this.addChart(chart);*/

    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(1000.0 * 60 * 60 /* 24*/); // 24 hrs

    plot.setDataset(1, dataset2);
    NumberAxis rangeAxis2 = new NumberAxis("%");
    rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(1, new DefaultXYItemRenderer());
    plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    ChartUtilities.applyCurrentTheme(chart);
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    chartPanel = new ChartPanel(chart);
}