C# 在c语言中使用ZedGraph#
A我有个问题。Zedgraph为我的方程式绘制了错误的图表 我的代码:C# 在c语言中使用ZedGraph#,c#,zedgraph,C#,Zedgraph,A我有个问题。Zedgraph为我的方程式绘制了错误的图表 我的代码: private void button1_Click(object sender, EventArgs e) { double a, b, c, dl; a = float.Parse(textBox1.Text); b = float.Parse(textBox2.Text); c = float.Parse(textBox3.Text); dl = (b * b) - (4 * a
private void button1_Click(object sender, EventArgs e)
{
double a, b, c, dl;
a = float.Parse(textBox1.Text);
b = float.Parse(textBox2.Text);
c = float.Parse(textBox3.Text);
dl = (b * b) - (4 * a * c);
if (dl < 0)
{
MessageBox.Show("Error");
}
else if (dl > 0)
{
x1 = (-b - Math.Sqrt(dl)) / (2 * a);
x2 = (-b + Math.Sqrt(dl)) / (2 * a);
textBox4.Text = x1.ToString();
textBox5.Text = x2.ToString();
}
else
{
string str = (b / (2 * a)).ToString();
textBox4.Text = str;
textBox5.Text = str;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
// This is to remove all plots
zedGraphControl1.GraphPane.CurveList.Clear();
// GraphPane object holds one or more Curve objects (or plots)
GraphPane myPane = zedGraphControl1.GraphPane;
PointPairList spl1 = new PointPairList();
// Add cruves to myPane object
LineItem myCurve1 = myPane.AddCurve("Equation", spl1, Color.Blue, SymbolType.None);
myCurve1.Line.Width = 5.0F;
myPane.Title.Text = "Graph";
for (int i = -5; i < 8; i++)
{
double y = (i - x1) * (i - x2);
spl1.Add(i, y);
}
//I add all three functions just to be sure it refeshes the plot.
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
}
private void按钮1\u单击(对象发送者,事件参数e)
{
双a、b、c、dl;
a=float.Parse(textBox1.Text);
b=float.Parse(textBox2.Text);
c=float.Parse(textBox3.Text);
dl=(b*b)-(4*a*c);
if(dl<0)
{
MessageBox.Show(“错误”);
}
else if(dl>0)
{
x1=(-b-数学Sqrt(dl))/(2*a);
x2=(-b+数学Sqrt(dl))/(2*a);
textBox4.Text=x1.ToString();
textBox5.Text=x2.ToString();
}
其他的
{
字符串str=(b/(2*a)).ToString();
textBox4.Text=str;
textBox5.Text=str;
}
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有无效按钮2\u单击(对象发送者,事件参数e)
{
//这是为了删除所有绘图
zedGraphControl1.GraphPane.CurveList.Clear();
//GraphPane对象包含一个或多个曲线对象(或曲线图)
GraphPane myPane=zedGraphControl1.GraphPane;
PointPairList spl1=新的PointPairList();
//将cruves添加到myPane对象
LineItem myCurve1=myPane.AddCurve(“方程式”,spl1,颜色.Blue,符号类型.None);
myCurve1.Line.Width=5.0F;
myPane.Title.Text=“图形”;
for(int i=-5;i<8;i++)
{
双y=(i-x1)*(i-x2);
spl1.添加(i,y);
}
//我添加了所有三个函数,只是为了确保它能参照绘图。
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
}
试试这个:
private void button2_Click(object sender, EventArgs e)
{
// This is to remove all plots
zedGraphControl1.GraphPane.CurveList.Clear();
// GraphPane object holds one or more Curve objects (or plots)
GraphPane myPane = zedGraphControl1.GraphPane;
PointPairList spl1 = new PointPairList();
LineItem lineItem = new LineItem("Equation");
myCurve1.Line.Width = 5.0F;
myPane.Title.Text = "Graph";
for (int i = -5; i < 8; i++)
{
double y = (i - x1) * (i - x2);
spl1.Add(i, y);
}
// Add cruves to myPane object
myCurve1 = myPane.AddCurve("Equation", spl1, Color.Blue, SymbolType.None);
//I add all three functions just to be sure it refeshes the plot.
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
}
private void按钮2\u单击(对象发送者,事件参数e)
{
//这是为了删除所有绘图
zedGraphControl1.GraphPane.CurveList.Clear();
//GraphPane对象包含一个或多个曲线对象(或曲线图)
GraphPane myPane=zedGraphControl1.GraphPane;
PointPairList spl1=新的PointPairList();
LineItem LineItem=新的LineItem(“方程式”);
myCurve1.Line.Width=5.0F;
myPane.Title.Text=“图形”;
for(int i=-5;i<8;i++)
{
双y=(i-x1)*(i-x2);
spl1.添加(i,y);
}
//将cruves添加到myPane对象
myCurve1=myPane.AddCurve(“方程式”,spl1,颜色。蓝色,符号类型。无);
//我添加了所有三个函数,只是为了确保它能参照绘图。
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
}
我移动了
行项目myCurve1=myPane.AddCurve(“等式”,spl1,Color.Blue,SymbolType.None)代码>在构建spl1
列表后完成。看看这是否适用于您这是一个错误,因为在declaredokay之前使用局部变量“myCurve1”。我编辑了代码。只需创建并初始化LineItem,然后将其用于此LineItem myCurve1=new LineItem()代码>添加时出错:LineItem myCurve1=new LineItem()…ZedGraph不包含构造函数编辑。使用此LineItem LineItem=新的LineItem(“公式”)代码>