List of usage examples for org.jfree.chart ChartFactory createBarChart3D
public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.YearStatisticPanel.java
public YearStatisticPanel() { setName("Jahr"); setLayout(new BorderLayout()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); HashMap<Integer, Integer> alarmCount = new HashMap<>(); try {/*from www .j av a2 s . c om*/ ResultSet resultSet = Starter.getDatabase().getStatement().executeQuery( "SELECT STARTDATE_YEAR, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY STARTDATE_YEAR" + " ORDER BY STARTDATE_YEAR ASC"); while (resultSet.next()) { alarmCount.put(resultSet.getInt("STARTDATE_YEAR"), resultSet.getInt("COUNT")); } } catch (SQLException e) { e.printStackTrace(); } Set<Integer> years = alarmCount.keySet(); for (Integer year : years) { Integer count = alarmCount.get(year); dataset.addValue(count, count, year); } JFreeChart chart = ChartFactory.createBarChart3D("Jahresbersicht", "Jahr", "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:Visao.grafico.Grafico.java
public void criaGrafico() { CategoryDataset cds = createDataset(); titulo = "Grfico de " + ControlePrincipal.tipo_grafico; String eixoy = "Valores"; String txt_legenda = "Ledenda:"; boolean legenda = true; boolean tooltips = true; boolean urls = true; graf = ChartFactory.createBarChart3D(ControlePrincipal.descricao, txt_legenda, eixoy, cds, PlotOrientation.VERTICAL, legenda, tooltips, urls); CategoryPlot plot = (CategoryPlot) graf.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(false); //ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, //TextAnchor.CENTER, TextAnchor.CENTER, 0.0); //renderer.setBasePositiveItemLabelPosition(p); /*ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0); renderer.setBasePositiveItemLabelPosition(p); ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0); renderer.setPositiveItemLabelPosition(p2);*/ CategoryItemRenderer line = plot.getRenderer(); //aqui definido o label line.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); line.setBaseItemLabelsVisible(true); line.setBaseItemLabelPaint(Color.BLACK); ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, 0.0);/*from w w w . j a va 2s . c om*/ line.setBasePositiveItemLabelPosition(p); myChartPanel = new ChartPanel(graf, true); myChartPanel.setSize(jPanel1.getWidth(), jPanel1.getHeight()); myChartPanel.setVisible(true); jPanel1.removeAll(); jPanel1.add(myChartPanel); jPanel1.revalidate(); jPanel1.repaint(); }
From source file:Classes_Home.CriarGrafico.java
public void criargrafico(JPanel jPanel3) { String pcs[] = { "'HP'", "'IBM'", "'LENOVO'", "'POSITIVO'", "'NACIONAL'" }; for (int i = 0; i <= 4; i++) { String query = "SELECT * FROM `cpu` WHERE marca = " + pcs[i]; try { st = connection.createStatement(); rs = st.executeQuery(query); if (rs.last()) { int aux = rs.getRow(); vetorParaGrafico[i] = aux; }/* w ww .j av a 2 s . co m*/ } catch (Exception e) { e.printStackTrace(); } } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(vetorParaGrafico[0], "Quantidade", "HP"); dataset.setValue(vetorParaGrafico[1], "Quantidade", "IBM"); dataset.setValue(vetorParaGrafico[2], "Quantidade", "LENOVO"); dataset.setValue(vetorParaGrafico[3], "Quantidade", "POSITIVO"); dataset.setValue(vetorParaGrafico[4], "Quantidade", "NACIONAL"); JFreeChart chart = ChartFactory.createBarChart3D(null, null, "Quantidade", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); CategoryItemRenderer renderer = p.getRenderer(); renderer.setSeriesPaint(0, new Color(80, 151, 204)); p.setRangeGridlinePaint(Color.BLACK); ChartPanel panel = new ChartPanel(chart); panel.setDomainZoomable(true); panel.setVisible(true); jPanel3.setLayout(new BorderLayout()); jPanel3.add(panel, BorderLayout.CENTER); jPanel3.revalidate(); jPanel3.repaint(); System.gc(); }
From source file:graficos.GenerarGraficoFinanciero.java
public void crear() { try {/*from ww w .j a va2s . co m*/ Dba db = new Dba(pathdb); db.conectar(); String sql = "select IdCategoria, Nombre from Categoria"; db.prepare(sql); db.query.execute(); ResultSet rs = db.query.getResultSet(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String fechai = periodo.substring(0, 10) + " 00:00:00"; String fechaf = periodo.substring(13, 23) + " 00:00:00"; while (rs.next()) { String sql1 = "select Monto from PagoCliente join FichaCliente on PagoCliente.IdFichaCliente=FichaCliente.IdFichaCliente" + " join Reservacion on Reservacion.IdReservacion=FichaCliente.IdReservacion join Habitacion on Reservacion.IdHabitacion=" + "Habitacion.IdHabitacion where Habitacion.IdCategoria=" + rs.getInt(1) + " and FichaCliente.FechaSalida>='" + fechai + "' and" + " FichaCliente.FechaSalida<='" + fechaf + "'"; db.prepare(sql1); db.query.execute(); ResultSet rs1 = db.query.getResultSet(); Double monto = 0.0; while (rs1.next()) { monto += rs1.getDouble(1); } dataset.setValue(monto, "Ingresos", rs.getString(2)); } JFreeChart chart = ChartFactory.createBarChart3D( "Comparacin de Ingresos por Categora\nPeriodo:" + periodo, "Categora", "Ingresos", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); // Get the Plot object for a bar graph p.setBackgroundPaint(Color.black); try { ChartUtilities.saveChartAsJPEG(new File(path), chart, 500, 300); } catch (Exception ee) { System.err.println(ee.toString()); System.err.println("Problem occurred creating chart."); } db.desconectar(); } catch (Exception e) { } }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.SchichtenBarChart.java
protected JFreeChart createBarChart(Object dataset) { final float plotForegroundAlpha = 0.6f; JFreeChart chart = ChartFactory.createBarChart3D(null, Messages.SchichtenBarChart_1, Messages.SchichtenBarChart_2, (CategoryDataset) dataset, PlotOrientation.HORIZONTAL, false, true, false);/*from w w w . j av a 2 s . c om*/ chart.setBackgroundPaint(Color.white); chart.getPlot().setForegroundAlpha(plotForegroundAlpha); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.STANDARD); return chart; }
From source file:Gui.Graficos.java
private void init(String titulo, String tituloX, String tituloY) { panel = new JPanel(); panel.setBackground(Color.WHITE); getContentPane().add(panel);//from w w w . j ava 2 s . co m // Creando el Grafico JFreeChart chart = ChartFactory.createBarChart3D(titulo, tituloX, tituloY, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new Color(225, 255, 228)); chart.getTitle().setPaint(Color.black); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.red); // Mostrar Grafico ChartPanel chartPanel = new ChartPanel(chart); panel.add(chartPanel); // panel.setLayout(new VerticalLayout()); panel.add(btAceptar); //panel. panel.setLayout(null); chartPanel.setBounds(100, 10, 1100, 600); btAceptar.setBounds(1065, 620, 130, 30); }
From source file:de.rbs90.fwdisp.settingsgui.gui.tabs.statistics.WeekDayStatisticsPanel.java
public WeekDayStatisticsPanel() { setName("Wochentag"); setLayout(new BorderLayout()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String weekDays[] = { "Mo", "Die", "Mi", "Do", "Fr", "Sa", "So" }; int alarmCount[] = new int[7]; try {//from w w w . ja va2 s. com ResultSet resultSet = Starter.getDatabase().getStatement().executeQuery( "SELECT STARTDATE_WEEKDAY, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY STARTDATE_WEEKDAY"); while (resultSet.next()) { alarmCount[resultSet.getInt("STARTDATE_WEEKDAY") - 1] = resultSet.getInt("COUNT"); } } catch (SQLException e) { e.printStackTrace(); } for (int i = 0; i < 7; i++) { String dayName; int dayNumber; if (i != 6) { dayNumber = i + 1; dayName = weekDays[i]; } else { dayName = weekDays[6]; //Sunday dayNumber = 0; } dataset.addValue(alarmCount[dayNumber], "", dayName); } JFreeChart chart = ChartFactory.createBarChart3D("Wochentagsbersicht", "Wochentag", "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.operamasks.faces.render.graph.BarChartRenderer.java
protected JFreeChart createChart(UIChart comp) { Dataset dataset = createDataset(comp); JFreeChart chart = null;/*from ww w . j a va2 s. com*/ if (dataset instanceof CategoryDataset) { if (comp.isStacked()) { if (comp.isEffect3D()) { chart = ChartFactory.createStackedBarChart3D(null, null, null, (CategoryDataset) dataset, getChartOrientation(comp), false, false, false); } else { chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset, getChartOrientation(comp), false, false, false); } } else { if (comp.isEffect3D()) { chart = ChartFactory.createBarChart3D(null, null, null, (CategoryDataset) dataset, getChartOrientation(comp), false, false, false); } else { chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset, getChartOrientation(comp), false, false, false); } } } else if (dataset instanceof IntervalXYDataset) { chart = ChartFactory.createXYBarChart(null, null, (dataset instanceof TimeSeriesCollection), null, (IntervalXYDataset) dataset, getChartOrientation(comp), false, false, false); } return chart; }
From source file:classes.SharedClass.java
public void getStatistics() { result = db.select("member", new String[] { " count(id) id" }, new String[] { "id" }, new String[] { "99999" }, "!=", "and"); try {/*w w w .jav a 2 s . com*/ if (result.next()) { memberId = result.getInt("id"); } } catch (SQLException ex) { Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } //book result = db.select("book", new String[] { "count(id)" }, new String[] { "id" }, new String[] { "99999" }, "!=", "and"); try { if (result.next()) { bookId = result.getInt(1); } } catch (SQLException ex) { Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex); } //operations result = db.select("operations", new String[] { "count(id)" }, new String[] { "type" }, new String[] { "borrowed" }, "=", "and"); try { if (result.next()) { operationsId = result.getInt(1); } } catch (SQLException ex) { Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex); } DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); dataSet.setValue(memberId, "Percent", "Members"); dataSet.setValue(bookId, "Percent", "Books"); dataSet.setValue(operationsId, "Percent", "Borrowe books"); JFreeChart chart = ChartFactory.createBarChart3D("Statistics", "Fields", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.yellow); chart.getTitle().setPaint(Color.red); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.blue); ChartFrame frame = new ChartFrame("Statistics", chart); frame.setLocationRelativeTo(null); frame.setSize(500, 550); frame.setVisible(true); }
From source file:Ventanas.VentanaVerGrafico.java
private void initGUI() { try {// w ww .java2s . co m this.setLayout(null); this.setIconImage( new ImageIcon(getClass().getClassLoader().getResource("Ventanas/is_a4af.gif")).getImage()); this.setTitle("Grfica"); this.setSize(705, 580); this.getContentPane().setBackground(new java.awt.Color(204, 230, 230)); this.setLocationRelativeTo(null); this.setResizable(false); { CategoryDataset dataset = createCategoryDataset(((Vector) VentanaVerEstadisticas.datosEstadistica)); JFreeChart chart = ChartFactory.createBarChart3D("Rendimiento de los operarios", "Operarios", "", dataset, PlotOrientation.HORIZONTAL, true, true, false); chart.setBackgroundPaint(new Color(204, 230, 230)); grafica = chart.createBufferedImage(700, 500); paint(grafica.getGraphics()); } } catch (Exception e) { e.printStackTrace(); } }