List of usage examples for org.jfree.chart ChartFrame ChartFrame
public ChartFrame(String title, JFreeChart chart)
From source file:teambootje.A5.java
/** * Creates new form A5/*from ww w .ja va 2 s . co m*/ */ public A5() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 5"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT Leeftijd, COUNT(*) AS Aantal FROM persoon GROUP BY Leeftijd"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String age = rs.getString("Leeftijd"); int aantal = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String leeftijd = age; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Niet vrijgegeven", a1); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per leeftijd", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mensen per leeftijd", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Leeftijd", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:userInterface.MonitoringTeamRole.EnvironmentJPanel.java
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked // TODO add your handling code here: JFreeChart chart = createChart(createDataset()); chart.setBackgroundPaint(Color.YELLOW); chart.getTitle().setPaint(Color.red); ChartFrame frame = new ChartFrame("XYChart", chart); frame.setVisible(true);//from ww w .j av a 2 s .com frame.setSize(450, 500); }
From source file:k_means.Kmeans.java
public void DisplayData() { for (int i = 0; i < dataSet.size(); i++) { System.out.println("X:" + dataSet.get(i).getX() + " Y:" + dataSet.get(i).getY() + " CLUSTER :" + dataSet.get(i).getCluster()); }//w w w . j ava 2 s.c o m XYDataset d = Plot.createDataset(dataSet, k); JFreeChart chart = ChartFactory.createScatterPlot("DataPlot", "X", "Y", d, PlotOrientation.VERTICAL, true, true, false); // create and display a frame... ChartFrame frame = new ChartFrame("First", chart); frame.pack(); frame.setVisible(true); }
From source file:org.jfree.chart.demo.XYStepChartDemo.java
/** * Displays a sample chart in its own frame. *//* w w w .java 2 s . com*/ private void displayChart() { if (this.frame == null) { // create a default chart based on some sample data... final String title = "LCACs in use at given time"; final String xAxisLabel = "Time"; final String yAxisLabel = "Number of Transports"; final XYDataset data = createStepXYDataset(); final JFreeChart chart = ChartFactory.createXYStepChart(title, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, true, // legend true, // tooltips false // urls ); // then customise it a little... chart.setBackgroundPaint(new Color(216, 216, 216)); final XYPlot plot = chart.getXYPlot(); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); // and present it in a frame... this.frame = new ChartFrame("Plan Comparison", chart); this.frame.pack(); RefineryUtilities.positionFrameRandomly(this.frame); this.frame.setVisible(true); } else { this.frame.setVisible(true); this.frame.requestFocus(); } }
From source file:org.jfree.chart.demo.MeterChartDemo.java
/** * Displays a meter chart./* w w w . j a v a 2 s . c o m*/ * * @param value the value. * @param shape the dial shape. */ void displayMeterChart(final double value, final DialShape shape) { final DefaultValueDataset data = new DefaultValueDataset(75.0); final MeterPlot plot = new MeterPlot(data); plot.setUnits("Degrees"); plot.setRange(new Range(20.0, 140.0)); // plot.setNormalRange(new Range(70.0, 100.0)); // plot.setWarningRange(new Range(100.0, 120.0)); // plot.setCriticalRange(new Range(120.0, 140.0)); plot.setDialShape(shape); plot.setNeedlePaint(Color.white); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 9)); // plot.setInsets(new Insets(5, 5, 5, 5)); final JFreeChart chart = new JFreeChart("Meter Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); // final MeterLegend legend = new MeterLegend("Sample Meter"); // chart.setLegend(legend); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final JFrame chartFrame = new ChartFrame("Meter Chart", chart); chartFrame.addWindowListener(new WindowAdapter() { /** * Invoked when a window is in the process of being closed. * The close operation can be overridden at this point. */ public void windowClosing(final WindowEvent e) { System.exit(0); } }); chartFrame.pack(); RefineryUtilities.positionFrameRandomly(chartFrame); chartFrame.setSize(250, 250); chartFrame.setVisible(true); }
From source file:view.PrograssCharts.java
/** * Creates new form PrograssCharts/*from w w w. j a va 2 s. c o m*/ */ public PrograssCharts(java.awt.Frame parent, boolean modal) { super(parent, modal); try { initComponents(); setSize(1400, 800); jPanel1.setVisible(false); jPanel2.setVisible(false); new Thread(new Runnable() { @Override public void run() { loading1(); loading2(); run(); } }).start(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset.setValue(QuestionLab.cat1, "gfdg", "Collectns"); dataset.setValue(QuestionLab.cat2, "gfdg", "Data"); dataset.setValue(QuestionLab.cat3, "gfdg", "Dev"); dataset.setValue(QuestionLab.cat4, "gfdg", "Excep"); dataset.setValue(QuestionLab.cat5, "gfdg", "File"); dataset.setValue(QuestionLab.cat6, "gfdg", "FlowCon"); dataset.setValue(QuestionLab.cat7, "gfdg", "Format"); dataset.setValue(QuestionLab.cat8, "gfdg", "GC"); dataset.setValue(QuestionLab.cat9, "gfdg", "IC"); dataset.setValue(QuestionLab.cat10, "gfdg", "VarArgs"); dataset.setValue(QuestionLab.cat11, "gfdg", "Fundamt"); dataset.setValue(QuestionLab.cat12, "gfdg", "Modif"); dataset.setValue(QuestionLab.cat13, "gfdg", "OOP"); dataset.setValue(QuestionLab.cat14, "gfdg", "Vari"); dataset.setValue(QuestionLab.cat15, "gfdg", "String"); dataset.setValue(QuestionLab.cat16, "gfdg", "Threads"); dataset.setValue(QuestionLab.cat17, "gfdg", "WC"); JFreeChart freeChart = ChartFactory.createBarChart("Exam Prograss by Subjects", "Subject", "Marks", dataset, PlotOrientation.VERTICAL, false, true, false); //JFreeChart freeChart1 = ChartFactory.createBarChart("Income", " Name", "Incomesss", dataset1, PlotOrientation.VERTICAL, false, true, false); TimeSeries pop = new TimeSeries("Population", Day.class); //JFreeChart chart=ChartFactory.create CategoryPlot plot = freeChart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Exam Prograss", freeChart); // frame.setVisible(true); // frame.setSize(550, 450); // JPanel jPanel1 = new JPanel(); jPanel1.setLayout(new java.awt.BorderLayout()); ChartPanel CP = new ChartPanel(freeChart); CP.setPreferredSize(new Dimension(785, 440)); CP.setMouseWheelEnabled(true); jPanel1.add(CP); jPanel1.revalidate(); ArrayList<Exam> setChartValue = ServerConnector.getServerConnector().getExamController() .getPreviousMarks(PracticeExamLogIn.studentNic); for (Exam exam : setChartValue) { //dataset1.setValue(exam.getMarks(), "gfdg9", exam.getDate()); pop.addOrUpdate(new Day(exam.getDate()), exam.getMarks()); System.out.println("mar" + exam.getMarks()); System.out.println("date" + exam.getDate()); } TimeSeriesCollection myDataset = new TimeSeriesCollection(); myDataset.addSeries(pop); JFreeChart myChart = ChartFactory.createTimeSeriesChart("Population Your Marks", "Date", "Population", myDataset, true, true, false); //try { //ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 500, 300); //} catch (IOException e) { //System.err.println("Problem occurred creating chart."); //} //JFreeChart chart=ChartFactory.create CategoryPlot plot1 = freeChart.getCategoryPlot(); plot1.setRangeGridlinePaint(Color.BLUE); //ChartFrame frame1 = new ChartFrame("Exam Prograss", freeChart1); // frame.setVisible(true); // frame.setSize(550, 450); // JPanel jPanel1 = new JPanel(); jPanel2.setLayout(new java.awt.BorderLayout()); ChartPanel CP1 = new ChartPanel(myChart); CP1.setPreferredSize(new Dimension(785, 440)); CP1.setMouseWheelEnabled(true); jPanel2.add(CP1); jPanel2.revalidate(); } catch (RemoteException | ClassNotFoundException | SQLException | NotBoundException | MalformedURLException ex) { Logger.getLogger(PrograssCharts.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:teambootje.A6.java
/** * Creates new form A6//w ww . j av a 2 s . c om */ public A6() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 6"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT Locatie.land, locatie.stad, count(persoon.LID) as Aantal FROM persoon, Locatie WHERE persoon.LID = locatie.LID GROUP BY stad"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String city = rs.getString("locatie.stad"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String c1 = city; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(c1, a1); pieDataset.setValue("Rotterdam", new Integer(1)); pieDataset.setValue("Bergen op zoom", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Waar komen bezoekers vandaan", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Waar komen bezoekers vandaan", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Land", "stad", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:teambootje.A3.java
/** * Creates new form A3/*from ww w .j a v a2 s.c o m*/ */ public A3() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 3"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT locatie.land, locatie.stad, COUNT(posts.PID) AS Aantal FROM persoon, locatie, posts WHERE persoon.LID = locatie.LID AND persoon.AID = posts.AID GROUP BY locatie.land ORDER BY count(posts.PID)"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String land = rs.getString("locatie.land"); String stad = rs.getString("locatie.stad"); int aantal = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String l1 = land; String s1 = stad; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(s1, a1); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per locatie", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per locatie", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Land", "Stad", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:teambootje.A7.java
/** * Creates new form A7//w w w.j a v a 2 s . co m */ public A7() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 7"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT doelgroep.doelgroep, COUNT(*) AS Aantal FROM doelgroep GROUP BY doelgroep.doelgroep"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String ta = rs.getString("doelgroep.Doelgroep"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String dd = ta; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dd, a1); pieDataset.setValue("Bedrijfsleven", new Integer(1)); pieDataset.setValue("50+", new Integer(1)); pieDataset.setValue("40+", new Integer(1)); pieDataset.setValue("30+", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per Doelgroep", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mensen per Doelgroep", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Doelgroep", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:teambootje.A8.java
/** * Creates new form A8//from w w w .j a va 2s . c o m */ public A8() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 8"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT doelgroep.Doelgroep, COUNT(posts.post) AS Aantal FROM doelgroep, posts WHERE posts.DID = doelgroep.DID GROUP BY doelgroep.Doelgroep"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String ta = rs.getString("doelgroep.Doelgroep"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String dd = ta; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dd, a1); pieDataset.setValue("50+", new Integer(0)); pieDataset.setValue("Tiener", new Integer(0)); pieDataset.setValue("40+", new Integer(0)); pieDataset.setValue("30+", new Integer(0)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per doelgroep", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per doelgroep", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Doelgoep", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }