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 WeekDayStatisticsPanel extends SecRowPanel { 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 { 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); } }