List of usage examples for org.jfree.data.statistics HistogramDataset setType
public void setType(HistogramType type)
From source file:utils.RandomVariable.java
public static void main(String[] args) { double[][] value = new double[2][100000]; for (int i = 1; i < 100000; i++) { //double v = RandomVariable.normal(0, 1); //double v = RandomVariable.cauchy(0, 1); //double v = RandomVariable.chi2(5); //double v = RandomVariable.exponential(1); // double v = RandomVariable.laplace(0, 1); // double v = RandomVariable.laplace(-3,1); //double v = RandomVariable.triangular(-6, -5, -3); double v = RandomVariable.weibull(4, 5); // if (v > 10 || v < -10) { // value[0][i] = 10d; // } else { // value[0][i] = v; // } //v = RandomVariable.laplace(-3,0.25); // v = RandomVariable.weibull(1, 1.5); if (v > 10 || v < -10) { value[1][i] = 10d;//from ww w . j a v a2 s . com } else { value[1][i] = v; } } int number = 40; HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries("Value 1", value[0], number); dataset.addSeries("Value 2", value[1], number); String plotTitle = "Histogram"; String xaxis = "number"; String yaxis = "value"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls); // int width = 500; // int height = 300; // try { // ChartUtilities.saveChartAsPNG(new File("histogram3.PNG"), chart, width, height); // } catch (IOException e) { // } //Display Chart ChartPanel chartPanel = new ChartPanel(chart); JFrame frame = new JFrame("Histogram plot demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(chartPanel); frame.pack(); frame.setVisible(true); }
From source file:com.jaxzin.iraf.demo.Main.java
private static IntervalXYDataset createData(final int count) { final HistogramDataset data = new HistogramDataset(); data.setType(HistogramType.SCALE_AREA_TO_1); data.addSeries("freq", createNormalDist(count, 0), (int) Math.round(Math.sqrt(count))); data.addSeries("rel_freq", createNormalDist(count, 2), (int) Math.round(Math.sqrt(count))); data.addSeries("area", createNormalDist(count, -2), (int) Math.round(Math.sqrt(count))); return data;// w w w.j a va2 s.c om }
From source file:es.uvigo.darwin.jmodeltest.io.RFHistogram.java
private static JFreeChart buildHistogram(double[] values, int steps, String plotTitle, String xAxis, String yAxis) {/*from w ww . java 2 s . c om*/ HistogramDataset hds = new HistogramDataset(); hds.setType(HistogramType.RELATIVE_FREQUENCY); hds.addSeries(1, values, steps); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram(plotTitle, xAxis, yAxis, hds, orientation, show, toolTips, urls); return chart; }
From source file:org.ect.reo.simulation.views.SimulationViewResults.java
private static JFreeChart createHistogram(Statistic statistic, Composite composite) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.RELATIVE_FREQUENCY); int numOfBatches = Integer.parseInt(SimulationViewOptions.batchNumberText.getText()); double[] values = new double[numOfBatches]; for (int i = 0; i < numOfBatches; i++) { values[i] = statistic.getStatisticValue(i); }/*from w ww. j a va2 s. c om*/ try { dataset.addSeries("Histogram of batch values", values, (int) Math.ceil(Math.log(numOfBatches) / Math.log(2) + 1)); return ChartFactory.createHistogram("Batch results", "Value", "Relative frequency", dataset, PlotOrientation.VERTICAL, false, true, false); } catch (Throwable t) { return null; } }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Build new histogram from the given numbers array using a default title and xLabel. * String dataName will be used for yLabel. * @param numbers Numbers for the histogram * @param dataName Name of the numbers data * @param divisions Divisions for the histogram * @return Prepared histogram/*from w ww.j ava 2 s . c om*/ */ public static JFreeChart buildHistogram(final Number[] numbers, final String dataName, final int divisions) { if (numbers == null || numbers.length == 0) { return null; } HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); double[] doubleNumbers = new double[numbers.length]; for (int i = 0; i < doubleNumbers.length; i++) { doubleNumbers[i] = numbers[i].doubleValue(); } dataset.addSeries(dataName, doubleNumbers, divisions > 0 ? divisions : 10);//Use 10 divisions if divisions number is invalid. JFreeChart histogram = ChartFactory.createHistogram(getMessage("ChartsUtils.report.histogram.title"), dataName, getMessage("ChartsUtils.report.histogram.yLabel"), dataset, PlotOrientation.VERTICAL, true, true, false); return histogram; }
From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java
public static void generateHistogram(String fileName, double[] value, int numberOfBins, String title, String xLabel, String yLabel) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(title, value, numberOfBins); String plotTitle = title;//from w w w. j a va 2 s . c o m String xaxis = xLabel; String yaxis = yLabel; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls); int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height); } catch (IOException e) { } }
From source file:simulation.AureoZauleckAnsLab2.java
public static JFreeChart createHistogram(ArrayList doubleMatrix, int width, String title, String label) { // Generate a one dimensional array of the size w*h of the double matrix ArrayList<Double> dataArrayList = new ArrayList<Double>(); for (int i = 0; i < doubleMatrix.size(); i++) { double value = Double.parseDouble(doubleMatrix.get(i).toString()); if (Double.isNaN(value)) continue; else/*from ww w . j a v a 2 s . c o m*/ dataArrayList.add(value); System.out.println(value); } double[] data = new double[dataArrayList.size()]; for (int p = 0; p < dataArrayList.size(); p++) data[p] = dataArrayList.get(p); // int number = data.length; HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries("Hist", data, width); String plotTitle = title; String yAxis = "Frequency"; String xAxis = label; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram(plotTitle, xAxis, yAxis, dataset, orientation, show, toolTips, urls); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); JFrame l = new JFrame(); l.setContentPane(chartPanel); l.setSize(400, 400); l.setVisible(true); return chart; }
From source file:ch.zhaw.ias.dito.ui.util.HistogramFrame.java
public HistogramFrame(Question q) { String title = Translation.INSTANCE.get("misc.graphic.histogram") + " " + q.getName(); setTitle(title);/*from w ww . ja v a2 s . c o m*/ HistogramDataset hist = new HistogramDataset(); hist.setType(HistogramType.FREQUENCY); Set<Double> values = new TreeSet<Double>(); q.getData().addValuesToCollection(values); int numOfBins = Math.min(values.size(), (q.getData().filteredLength() / 20) + 10); hist.addSeries(q.getName(), q.getData().getValues(), numOfBins); JFreeChart chart = ChartFactory.createHistogram(title, Translation.INSTANCE.get("misc.graphic.value"), Translation.INSTANCE.get("misc.graphic.frequency"), hist, PlotOrientation.VERTICAL, false, true, false); this.add(new ChartPanel(chart), BorderLayout.CENTER); this.setSize(300, 300); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setVisible(true); }
From source file:iad.gui.HistogramDialog.java
private JFreeChart buildHistogram(final String title, final String xAxisLabel, final String yAxisLabel, final double[] numbers, final int div, final HistogramType type) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(type); dataset.addSeries(xAxisLabel, numbers, div); JFreeChart histogram = ChartFactory.createHistogram(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); return histogram; }
From source file:pertchart.Histogram.java
public JFreeChart createHistorgram(double[] data) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.RELATIVE_FREQUENCY); dataset.addSeries("Histogram", data, this.bins); String plotTitle = "Project Completion Times"; String xaxis = "Completion Times"; String yaxis = ""; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, dataset, orientation, show, toolTips, urls);//from w ww .ja v a 2s .com int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File("histogram.png"), chart, width, height); } catch (Exception e) { System.out.println(e); } return chart; }