/* * Copyright (C) 2013 Serdar * * This program 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 3 of the License, or * (at your option) any later version. * * This program 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. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.fub.maps.project.detector.model.statistics; import de.fub.utilsmodule.text.CustomNumberFormat; import java.awt.BorderLayout; import java.awt.Color; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.labels.StandardXYItemLabelGenerator; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.StandardXYBarPainter; import org.jfree.chart.renderer.xy.XYBarRenderer; import org.jfree.data.statistics.HistogramDataset; /** * * @author Serdar */ public class HistogramPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; private final HistogramDataset dataSet = new HistogramDataset(); // NO18N private final JFreeChart histogramChart; private final XYPlot plot; private final ChartPanel chartPanel; /** * Creates new form histogramPanel */ public HistogramPanel() { initComponents(); histogramChart = ChartFactory.createHistogram(null, null, null, dataSet, PlotOrientation.VERTICAL, false, true, true); plot = histogramChart.getXYPlot(); chartPanel = new ChartPanel(histogramChart, true); add(chartPanel, BorderLayout.CENTER); XYBarRenderer barRenderer = new XYBarRenderer(.05); barRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); barRenderer.setBarPainter(new StandardXYBarPainter()); barRenderer.setBarAlignmentFactor(.1); barRenderer.setBasePaint(Color.blue); // barRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); barRenderer.setBaseItemLabelGenerator( new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, new CustomNumberFormat(), new CustomNumberFormat())); barRenderer.setBaseItemLabelsVisible(true); plot.setRenderer(barRenderer); plot.setBackgroundPaint(Color.white); histogramChart.setBackgroundPaint(Color.white); plot.setRangeGridlinesVisible(true); chartPanel.setVerticalAxisTrace(false); chartPanel.setDisplayToolTips(true); chartPanel.setBackground(Color.white); } public HistogramDataset getDataSet() { return dataSet; } public JFreeChart getHistogramChart() { return histogramChart; } public XYPlot getPlot() { return plot; } public ChartPanel getChartPanel() { return chartPanel; } public ValueAxis getDomainAxis() { return plot.getDomainAxis(); } public ValueAxis getRangeAxis() { return plot.getRangeAxis(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { setLayout(new java.awt.BorderLayout()); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables }