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:loldmg.GUI.MainFrame.java

/**
 * Creates new form MainFrame// w  w  w  . j a  v a2  s .co  m
 */
public MainFrame() {
    initComponents();
    Instance = this;
    DPSButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            GraphPanel.removeAll();
            chart = createChart(createDataset((Champion) championComboBox.getSelectedItem(),
                    (Champion) targetComboBox.getSelectedItem()));
            ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setSize(new java.awt.Dimension(700, 450));
            chartPanel.setVisible(true);
            GraphPanel.add(chartPanel);
            GraphPanel.setSize(chartPanel.getSize());
            pack();
        }
    });

}

From source file:com.wsntools.iris.tools.Graph.java

public Graph(Model model) {

    this.model = model;

    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, true,
            true, false);//from  w  ww.  j a va 2s  . co m

    chartPanel = new ChartPanel(chart);
    setupChartType(chart);

    this.setLayout(new BorderLayout());
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:Interface.ResultadoJanela.java

public ResultadoJanela(List<Resultado> tar, List<Resultado> jac, List<Resultado> och, List<Resultado> sbi) {
    //  super("Resultado");
    CategoryDataset dataset;/*from w w w .  j a  va  2  s  . c om*/

    //---------------------gerando resultados tarantula-------------------------------------
    dataset = gerarDataset(tar, jac, och, sbi);
    JFreeChart chart = gerarGrafico(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);

    JLabel lAjuda = new JLabel("Ajuda", JLabel.RIGHT);
    lAjuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icone_informacao.gif"))); // NOI18N
    lAjuda.setPreferredSize(new Dimension(50, 50));
    lAjuda.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            lAjudaMouseClicked(evt);
        }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(lAjuda, BorderLayout.BEFORE_FIRST_LINE);
    panel.add(chartPanel, BorderLayout.LINE_START);
    JLabel lTabela = new JLabel("Tabela de Resultados", JLabel.CENTER);
    panel.add(lTabela, BorderLayout.SOUTH);

    JTable table = new JTable(criarValores(tar, jac, och, sbi), criarColunas());

    // Adiciona o JTable dentro do painel
    JScrollPane scrollPane = new JScrollPane(table);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    panel.add(scrollPane, BorderLayout.SOUTH);

    JFrame frame = new JFrame();
    frame.setTitle("JLoc - Resultado");
    frame.setVisible(true);
    frame.add(panel);

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

From source file:com.sixrr.metrics.ui.charts.PieChartDialog.java

public PieChartDialog(Project project, String metricName, String metricTypeName, String[] measuredItems,
        Double[] values) {/*w ww  .  ja  va2s. c o  m*/
    super(project, true);
    this.metricName = metricName;
    this.metricTypeName = metricTypeName;
    this.measuredItems = measuredItems.clone();
    this.values = values.clone();
    final PieDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    init();
}

From source file:Software_Jframes.chart.java

public void piechart(JDesktopPane jDesktopPane1, String pid) {

    DefaultPieDataset piedataset = new DefaultPieDataset();
    try {//from   www .  j a  va2 s.c  om
        ResultSet rs = db.statement()
                .executeQuery("select name,cost from project_level_payment where projectid='" + pid + "' ");
        while (rs.next()) {
            String cost = rs.getString("cost");
            int cost_int1 = Integer.parseInt(cost);

            String name = rs.getString("name");

            piedataset.setValue(name, new Integer(cost_int1));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    JFreeChart chart = ChartFactory.createPieChart("Costs for Project", piedataset, true, true, true);
    PiePlot p = (PiePlot) chart.getPlot();
    p.setBackgroundPaint(Color.white);
    ChartPanel panel = new ChartPanel(chart);
    jDesktopPane1.add(panel).setSize(440, 300);
}

From source file:trendgraph.XYLineChart_AWT.java

public XYLineChart_AWT(int yearStart, int yearEnd, String[] creditUnionName, String columnName)
        throws SQLException {
    super("Graph");
    super.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.yearStart = yearStart;
    this.yearEnd = yearEnd;
    this.creditUnionName = creditUnionName;
    this.columnName = columnName;
    saveGraphButton = new JButton("Save Graph");
    saveGraphButton.setBorderPainted(false);
    saveGraphButton.setFocusPainted(false);

    JFreeChart xylineChart = ChartFactory.createXYLineChart("CU Report", "Year (YYYY)", //X-axis
            columnName, //Y-axis (replace with columnName
            createDataset(), PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 800)); //(x, y)
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesPaint(0, Color.RED); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(0, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(1, Color.BLUE); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(1, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(2, Color.GREEN); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(2, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(3, Color.yellow); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(3, new BasicStroke(3.0f)); //Font size

    plot.setRenderer(renderer);/*from  w w w. j  ava 2s  . c  o m*/
    chartPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    chartPanel.add(saveGraphButton);
    setContentPane(chartPanel);
    pack();
    RefineryUtilities.centerFrameOnScreen(this);
    setVisible(true);

    saveGraphButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Rectangle rect = chartPanel.getBounds();
            FileChooser chooser = new FileChooser();

            //get chosen path and save the variable
            String path = chooser.getPath();
            path = path.replace("\\", "/");

            String format = "png";
            String fileName = path + "." + format;
            BufferedImage captureImage = new BufferedImage(rect.width, rect.height,
                    BufferedImage.TYPE_INT_ARGB);
            chartPanel.paint(captureImage.getGraphics());

            File file = new File(fileName);

            try {
                ImageIO.write(captureImage, format, file);

                //write data to file
            } catch (IOException ex) {
                Logger.getLogger(XYLineChart_AWT.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.TimeStatisticsPanel.java

public TimeStatisticsPanel() {
    setName("Uhrzeit");

    setLayout(new BorderLayout());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int alarmCount[] = new int[24];

    try {//  ww  w  .ja  v a2 s  .co m
        ResultSet resultSet = Starter.getDatabase().getStatement().executeQuery(
                "SELECT STARTTIME_HOUR, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY STARTTIME_HOUR");

        while (resultSet.next()) {
            alarmCount[resultSet.getInt("STARTTIME_HOUR")] = resultSet.getInt("COUNT");
        }

    } catch (SQLException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < 24; i++) {
        dataset.addValue(alarmCount[i], "", "" + i);
    }

    JFreeChart chart = ChartFactory.createBarChart3D("Zeitbersicht", "Uhrzeit", "Einstze", dataset,
            PlotOrientation.VERTICAL, false, false, false);

    chart.setBackgroundPaint(getBackground());

    ChartPanel panel = new ChartPanel(chart);
    panel.setPopupMenu(null);
    add(panel, BorderLayout.CENTER);
}

From source file:org.mwc.debrief.sensorfusion.views.MouseClickProblemDemo.java

/**
 * @param title// w  w  w  . j a v a2 s.  co m
 *          the frame title.
 */
public MouseClickProblemDemo(final String title) {
    super(title);

    final TimeSeries s1 = new TimeSeries("Series to click");
    s1.add(new Month(2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("[Alt]-click to switch orientation", // title
            "Time axis", // x-axis label
            "Value axis", // y-axis label
            dataset, // data
            false, // create legend?
            false, // generate tooltips?
            false // generate URLs?
    );

    final ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    chartPanel.addChartMouseListener(new ChartMouseListener() {
        public void chartMouseMoved(final ChartMouseEvent arg0) {
        }

        public void chartMouseClicked(final ChartMouseEvent arg0) {
            System.out.println("clicked on:" + arg0.getEntity());

            if (arg0.getTrigger().isAltDown()) {
                if (chart.getXYPlot().getOrientation() == PlotOrientation.HORIZONTAL)
                    chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
                else
                    chart.getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
            }
        }
    });
    setContentPane(chartPanel);
}

From source file:uk.ac.lkl.cram.ui.chart.AbstractChartMaker.java

/**
 * Create the chart panel from a module//w w  w. j ava2  s. c  o m
 * @param m the module from which to create the chart
 * @return the chart panel created from the module
 */
private ChartPanel createChartPanel() {
    //Create the chart from the dataset
    JFreeChart chart = createChart();
    setChartDefaults(chart);
    //Create the chartpanel to render the chart
    return new ChartPanel(chart);
}

From source file:grafix.telas.TelaComparativos.java

private void atualizarGrafico() {
    Vector<IndiceComparativo> indices = gerarIndices();
    construtor = new ConstrutorGraficoComparativos(indices);
    panelGrafico.removeAll();/*www .jav  a 2s  . c o m*/
    chartPanel = new ChartPanel(construtor.criarJFreeChart());
    panelGrafico.add(chartPanel);
    panelGrafico.revalidate();
    panelGrafico.repaint();
    this.repaint();
}