Java tutorial
/******************************************************************************* * FWDisp - https://github.com/rbs90/FWDisp * * Copyright (C) 2012 Robert Schoenherr * * FWDisp is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * FWDisp is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. ******************************************************************************/ package de.rbs90.fwdisp.settingsgui.gui.tabs.statistics; import de.rbs90.fwdisp.Starter; import de.rbs90.fwdisp.settingsgui.gui.moduls.SecRowPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import java.awt.*; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; /** * @author rbs */ public class MonthlyStatisticPanel extends SecRowPanel { public MonthlyStatisticPanel() { setName("Monat"); setLayout(new BorderLayout()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int alarmCount[] = new int[12]; try { ResultSet resultSet = Starter.getDatabase().getStatement().executeQuery( "SELECT STARTDATE_MONTH, COUNT(*) AS COUNT FROM ALARMHISTORY GROUP BY STARTDATE_MONTH"); while (resultSet.next()) { alarmCount[resultSet.getInt("STARTDATE_MONTH") - 1] = resultSet.getInt("COUNT"); } } catch (SQLException e) { e.printStackTrace(); } for (int i = 0; i < 12; i++) { dataset.addValue(alarmCount[i], "", "" + (i + 1)); } JFreeChart chart = ChartFactory.createBarChart3D("Monatsbersicht", "Monat", "Einstze", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(getBackground()); ChartPanel panel = new ChartPanel(chart); panel.setPopupMenu(null); add(panel, BorderLayout.CENTER); } }