Combine Histogram and NormalDistributionFunction

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Huesitos
Posts: 1
Joined: Mon Jun 27, 2016 11:13 am
antibot: No, of course not.

Combine Histogram and NormalDistributionFunction

Post by Huesitos » Mon Jun 27, 2016 11:50 am

Hi. first sorry for my bad English.

I have looked everywhere, but find nothing :cry:

I need to combine two graphics. A histogram and a graph of normal distribution.

ImageImage

I've tried everything, but nothing...

My code is:

Code: Select all

    public void mostrarHistograma()
    {
        ChartFrame f  = new ChartFrame("Histograma", chart);
        f.pack();
        f.setVisible(true);
    }
    
    private static void getDistNormal()
    {
        NormalDistributionFunction2D normal = new NormalDistributionFunction2D(0, 1.0);
        XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -2.5, 2.5, 50, "Normal");
        JFreeChart chart = ChartFactory.createXYLineChart("Normal", "x", "y", dataset, PlotOrientation.VERTICAL, true, true, false);
        ChartFrame f  = new ChartFrame("Histograma", chart);
        f.pack();
        f.setVisible(true);
    }
    
    private static JFreeChart getHistogram(double [] datos)
    {
        JFreeChart chart1 = ChartFactory.createHistogram("TCL", "X", "Y", crearDataset(datos), PlotOrientation.VERTICAL, false, false, false);
        getDistNormal();
        return chart1;
        
    }
    
    private static HistogramDataset crearDataset(double [] datos)
    {
        HistogramDataset dataset = new HistogramDataset();
        dataset.addSeries("Histograma", datos, (int) Math.sqrt(datos.length));
        return dataset;
    }

I need your help

Thank you very much!!

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Combine Histogram and NormalDistributionFunction

Post by John Matthews » Wed Jun 29, 2016 3:56 pm

Look under Overlaid Charts in the demo.

Locked