HistogramDataset dataSet = new HistogramDataset(); dataSet.setType(HistogramType.FREQUENCY); dataSet.addSeries("Hibernate", Doubles.toArray(values), 1000);
dataset.setType(HistogramType.RELATIVE_FREQUENCY); dataset.addSeries("Hist",data,200); // Number of bins is 50 String plotTitle = "";
/** Return the JFreeChart with this histogram, and as a side effect, show it in a JFrame * that provides the means to edit the dimensions and also the plot properties via a popup menu. */ public JFreeChart asChart(final boolean show) { double[] d = new double[this.size()]; int i = 0; for (Number num : this.values()) d[i++] = num.doubleValue(); HistogramDataset hd = new HistogramDataset(); hd.setType(HistogramType.RELATIVE_FREQUENCY); String title = "Histogram"; hd.addSeries(title, d, d.length); JFreeChart chart = ChartFactory.createHistogram(title, "", "", hd, PlotOrientation.VERTICAL, false, false, false); setTheme(chart); if (show) { JFrame frame = new JFrame(title); frame.getContentPane().add(new ChartPanel(chart)); frame.pack(); frame.setVisible(true); } return chart; }
private static JFreeChart createHistogram(List<Double> samples) { double[] data = new double[samples.size()]; for (int i = 0; i < samples.size(); i++) { data[i] = samples.get(i); } // int number = data.length; HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.RELATIVE_FREQUENCY); dataset.addSeries("Hist", data, 200); String plotTitle = ""; String xAxis = "Value"; String yAxis = "Frequency"; 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); return chart; }
dataset.setType(HistogramType.FREQUENCY);
public void createRelativeChart(String pngFileName){ HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.RELATIVE_FREQUENCY); double [] values = getValuesBetween(getMinScore(), getMaxScore()); dataset.addSeries(getTitle(), values,getNumberOfBars(),getMinScore(),getMaxScore()); String plotTitle = getTitle(); String xaxis = "Score"; String yaxis = "% of interactions"; 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); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setAutoRange(true); try { ChartUtilities.saveChartAsPNG(new File(pngFileName), chart, getWidth(), getHeight()); } catch (IOException e) { e.printStackTrace(); } }
public void createChart(String pngFileName){ HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); double [] values = getValuesBetween(getMinScore(), getMaxScore()); dataset.addSeries(getTitle(), values,getNumberOfBars(),getMinScore(),getMaxScore()); String plotTitle = getTitle(); String xaxis = "Score"; String yaxis = "Number of interactions"; 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); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setAutoRange(true); try { ChartUtilities.saveChartAsPNG(new File(pngFileName), chart, getWidth(), getHeight()); } catch (IOException e) { e.printStackTrace(); } }