我正在尝试学习C#,作为自己的练习,我编写了Box-Muller方法,现在我正在尝试绘制模拟数据点的直方图,以检查数据是否看起来相当正常。
要创建直方图,我在此处遵循本指南:http://www.i-programmer.info/programming/uiux/2756-getting-started-with-net-charts.html
到目前为止,我已将我的代码包含在内。我的问题是我在main方法的“chart1”下得到了波浪形的红线,我得到错误“当前上下文中不存在名称'chart1'。我似乎没有指南中缺少任何内容谁能清理我错过的东西?
最好的问候。
using System;
using System.Windows.Forms.DataVisualization.Charting;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
double[] normalData = new double[200];
for (int i = 1; i <= 100; i++)
{
Tuple<double, double> Z = BoxMuller(i);
normalData[2 * i - 2] = Z.Item1;
normalData[2 * i - 1] = Z.Item2;
//Console.WriteLine("{0} {1}", normalData[2 * i - 2], normalData[2 * i - 1]);
}
//Trying to make a simple histogram (to begin with)
DataPoint Dp = new DataPoint();
Dp.SetValueY(3);
chart1.Series.Clear();
chart1.Series.Add("My Data");
}
static Tuple<double, double> BoxMuller(int i)
{
Random rand = new Random(i);
double U1 = rand.NextDouble();
double U2 = rand.NextDouble();
double R = -2 * Math.Log(U1);
double V = 2 * Math.PI * U2;
double Z1 = Math.Sqrt(R) * Math.Cos(V);
double Z2 = Math.Sqrt(R) * Math.Sin(V);
Tuple<double, double> tuple = new Tuple<double, double>(Z1, Z2);
return tuple;
}
}
}