ComponentOne Chart for WPF and Silverlight
Chart for WPF and Silverlight / Chart Types / Special Chart Types and Combination Charts / Creating a Gaussian Curve
In This Topic
    Creating a Gaussian Curve
    In This Topic

    A Gaussian or normal curve is used to show a distribution of probability over the values of a random variable.

    To create a Gaussian Curve in C1Chart, use the following code:

    C#
    Copy Code
      // create and add to the chart data series representing Gaussian function
        //   y(x) = a * exp( -(x-b)*(x-b) / (2*c*c))
        // in the interval from x1 to x2
        void CreateGaussian(double x1, double x2, double a, double b, double c)
        {
          // number of points
          int cnt = 200;       var xvals = new double[cnt];
          var yvals = new double[cnt];
    
          double dx = (x2 - x1) / (cnt-1);
    
          for (int i = 0; i < cnt; i++)
          {
            var x = x1 + dx * i;
            xvals[i] = x;
            x =  (x - b) / c;
            yvals[i] = a * Math.Exp(-0.5*x*x);
          }
    
          var ds = new XYDataSeries()
          {
            XValuesSource = xvals,
            ValuesSource = yvals,
            ChartType = ChartType.Line
          };
    
          chart.Data.Children.Add(ds);
        }
    
    See Also