Hi,

Is there a frequency function in C# like there is in Excel. I need to show a distribution chart in bell curve form.


Thanks

This library entry at msdn.microsoft.com might get you closer to what you're looking for if you're looking for a graphical output based on your data. At the least it should get you closer to what you need even if you need to modify the sample method they provide to fit your needs.

Hope this helps :) Please mark as solved if it resolves your issue.

@Lusiphur: The LinearGradientBrush is used to fill a shape using linear shading. It does not draw a curved line. This will not help.
I don't think there is anything native to .Net that supports drawing bell curves.
May be someone else can help.

I was tossing the only thing I could find in there since I, also, don't know of anything in .Net that does "exactly" what they're looking for. You can't expect all of my posts to be gold can you? :P

It is really hot overhere(34°C) but I still managed to do a bit of programming. Having no swimming pool around, what else can a man do? ;)
So here it is, hope it helps.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] D = { 5, 2, 7, 8, 11, 12, 3, 1, 2, 10 };
            double[] B = { 4, 8 };
            double[] F = FREQUENCY(D, B);
            for (int i = 0; i < F.Length; i++)
            {
                Console.WriteLine(F[i]);
            }           
            Console.WriteLine(NORMDIST(1,42,1.5,false));
            Console.ReadKey();
        }

        // QAD, so little error checking
        public static double[] FREQUENCY(double[] Data, double[] Bins)
        {
            double[] FreqList = new double[Bins.Length + 1];
            for (int i = 0; i < FreqList.Length; i++)
            {
                FreqList[i] = 0.0; //init our list
            }
            for (int i = 0; i < Data.Length; i++)
            {
                for (int j = 0; j < Bins.Length; j++)
                {
                    if (Data[i] <= Bins[j])
                    {
                        FreqList[j]++;
                        break; // we don't want to fill others
                    }
                }
                if (Data[i] > Bins[Bins.Length - 1])
                {
                    FreqList[Bins.Length]++;
                }
            }
            return FreqList;
        }

        //evaluation of the bell curve. See http://en.wikipedia.org/wiki/Normal_distribution
        public static double NORMDIST(double x, double mean, double standard_dev, bool cumulative)
        {
            double fact = standard_dev * Math.Sqrt(2.0 * Math.PI);
            double expo = (x - mean) * (x - mean) / (2.0 * standard_dev * standard_dev);
            //if (cumulative) do integration from 0 to x
            //look at this snippet for A way not THE way to do this:
            //http://www.daniweb.com/code/snippet217197.html
            //else just return the value:
            return Math.Exp(-expo) / fact;
        }
    }
}
commented: Now THAT's what I'm talkin' 'bout! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.