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; /** * @author rbs */ public class TimeStatisticsPanel extends SecRowPanel { public TimeStatisticsPanel() { setName("Uhrzeit"); setLayout(new BorderLayout()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int alarmCount[] = new int[24]; try { 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); } }