作者:手机用户2602880745 | 来源:互联网 | 2023-05-17 14:00
我在一个FORM上放了四个Chart控件,当改换点击一个菜单时,界面上根据需要画出最多四个图(动态的,有时只三个图),我现在已经完成对三个点击菜单动作的编程,但是当我轮换点击三个菜单时,会随机性
我在一个FORM上放了四个Chart控件, 当改换点击一个菜单时, 界面上根据需要画出最多四个图(动态的,有时只三个图),我现在已经完成对三个点击菜单动作的编程, 但是当我轮换点击三个菜单时,会随机性的出现错误信息"轴界限最大值Axis Maximum小于最小值Axis Minimum", 请注意是随机的,即有时有这个错误,有时没有, 有时是点击这个键(某四个组图)出问题,有时则是其它图出问题(有个规律是总出在Ch3上, 当屏蔽了Ch3时,又出现在Ch4上), 而我也检查了坐标轴最大最小值(程序中是axmax, axmin),不存在那种可能(axmax
太长发不完, 只附上一个菜单点击事件(某些语句精简了)并做了并行处理, 如果需要其它几个可以给我EMAIL:luchj@isu.edu
7 个解决方案
程序下续:
void __fastcall TMainform::ViewP_plot2Click(TObject *Sender)
{ int i,j;
double ax,ay,axmax,axmin,aymax,aymin;
double tmp1[21],tmp2[21],tmp3[21],tmp4[21];
Ch1->Left=Splitter->Left+Splitter->Width;
Ch1->Top=Splitter->Top;
Ch1->Height=Splitter->Height/2;
Ch1->Width=(Mainform->ClientWidth-PControl->Width-Splitter->Width)/2;
Ch2->Left =Ch1->Left+Ch1->Width;
Ch2->Top =Ch1->Top;
Ch2->Height=Ch1->Height;
Ch2->Width =Mainform->ClientWidth-PControl->Width-Splitter->Width - Ch1->Width;
Ch3->Left =Ch1->Left;
Ch3->Top =Splitter->Height/2;
Ch3->Height=Mainform->ClientHeight-Ch1->Height;
Ch3->Width =Ch1->Width;
Ch4->Left =Ch2->Left; Ch4->Top =Ch3->Top;
Ch4->Height=Ch3->Height; Ch4->Width =Ch2->Width;
Ch1->Visible=true; Ch2->Visible=true; Ch3->Visible=true; Ch4->Visible=true;
Ch1->FreeAllSeries(); Ch2->FreeAllSeries(); Ch3->FreeAllSeries();
Ch4->FreeAllSeries();
//此处略去对tmp1~tmp4的赋值;
axmax=-1000000; axmin= 1000000; aymax=-1000000; aymin= 1000000;
for(j=0;j { axmax=max(axmax,tmp1[j]); axmin=min(axmin,tmp1[j]);
aymax=max(aymax,tmp2[j]); aymin=min(aymin,tmp2[j]);
axmax=max(axmax,tmp3[j]); axmin=min(axmin,tmp3[j]);
aymax=max(aymax,tmp4[j]); aymin=min(aymin,tmp4[j]);
axmax=max(axmax,XSTN[j]); axmin=min(axmin,XSTN[j]);
aymax=max(aymax,RSTN[j]); aymin=min(aymin,RSTN[j]);
axmax=max(axmax,XGCN[j]); axmin=min(axmin,XGCN[j]);
aymax=max(aymax,RGCN[j]); aymin=min(aymin,RGCN[j]);
}
ax=axmax-axmin; ay=aymax-aymin;
axmax=axmax+ax*0.02; axmin=axmin-ax*0.02;
aymax=aymax+ay*0.10; aymin=aymin-ay*0.02;
Ch1->Title->Text->SetText("Blade Meridional Projection");
Ch1->BottomAxis->Title->Caption="X(m)";
Ch1->LeftAxis->Title->Caption ="R(m)";
Ch1->LeftAxis->Maximum=aymax;
Ch1->LeftAxis->Minimum=aymin;
Ch1->BottomAxis->Maximum=axmax;
Ch1->BottomAxis->Minimum=axmin;
Ch1->Legend->Visible=true;
Ch1->Legend->Color=clBtnFace;
Ch1->Legend->ColorWidth = 40;
Ch1->Legend->Frame->Visible = false;
Ch1->Legend->HorizMargin = 2;
Ch1->Legend->ResizeChart = false;
Ch1->Legend->ShadowSize = 0;
Ch1->Legend->TextStyle = ltsPlain;
Ch1->Legend->TopPos = 14;
Ch1->Legend->VertMargin = 2 ;
s_1[0] = new TLineSeries(this);
s_1[0]->Title = "LE";
s_1[0]->VertAxis = aLeftAxis;
s_1[0]->XValues->Order = loNone;
s_1[0]->YValues->Order = loNone;
s_1[0]->SeriesColor = clRed; //线的颜色
s_1[0]->Pointer->Brush->Color =clRed; //标注的填充颜色
s_1[0]->Pointer->InflateMargins = true;
s_1[0]->Pointer->Pen->Color = clRed; //标注的外圈颜色
s_1[0]->Pointer->Style = psRectangle;
s_1[0]->Pointer->HorizSize= 3;
s_1[0]->Pointer->VertSize = 3;
s_1[0]->Pointer->Visible = true;
for(i=0;i { s_1[0]->AddXY(tmp1[i]+STACKX,tmp2[i],"",clRed);
}
s_1[1] = new TLineSeries(this);
s_1[1]->Title = "STK";
s_1[1]->VertAxis = aLeftAxis;
s_1[1]->XValues->Order = loNone;
s_1[1]->YValues->Order = loNone;
s_1[1]->SeriesColor = clRed;
s_1[1]->Pointer->Brush->Color = clBtnFace;
s_1[1]->Pointer->InflateMargins = true;
s_1[1]->Pointer->Pen->Color = clRed;
s_1[1]->Pointer->Style = psCircle;
s_1[1]->Pointer->HorizSize= 4;
s_1[1]->Pointer->VertSize = 4;
s_1[1]->Pointer->Visible = true;
for(i=0;i { s_1[1]->AddXY(XSTN[i]+STACKX,RSTN[i],"",clRed);
}
s_1[2] = new TLineSeries(this);
s_1[2]->Title = "CG";
s_1[2]->VertAxis = aLeftAxis;
s_1[2]->XValues->Order = loNone;
s_1[2]->YValues->Order = loNone;
s_1[2]->SeriesColor = clRed; //线的颜色
s_1[2]->Pointer->Brush->Color =clBtnFace; //标注的填充颜色
s_1[2]->Pointer->InflateMargins = true;
s_1[2]->Pointer->Pen->Color = clRed; //标注的外圈颜色
s_1[2]->Pointer->Style = psRectangle;
s_1[2]->Pointer->HorizSize= 3;
s_1[2]->Pointer->VertSize = 3;
s_1[2]->Pointer->Visible = true;
for(i=0;i { s_1[2]->AddXY(XGCN[i]+STACKX,RGCN[i],"",clRed);
}
s_1[3] = new TLineSeries(this);
s_1[3]->Title = "TE";
s_1[3]->VertAxis = aLeftAxis;
s_1[3]->XValues->Order = loNone;
s_1[3]->YValues->Order = loNone;
s_1[3]->SeriesColor = clRed;
s_1[3]->Pointer->Brush->Color = clRed;
s_1[3]->Pointer->InflateMargins = true;
s_1[3]->Pointer->Pen->Color = clRed;
s_1[3]->Pointer->Style = psCircle;
s_1[3]->Pointer->HorizSize= 4;
s_1[3]->Pointer->VertSize = 4;
s_1[3]->Pointer->Visible = true;
for(i=0;i { s_1[3]->AddXY(tmp3[i]+STACKX,tmp4[i],"",clRed);
}
for(j=0;j<4;j++)
{ Ch1->AddSeries(s_1[j]);
}
axmax=-1000000; axmin= 1000000; aymax=-1000000; aymin= 1000000;
for(j=0;j { axmax=max(axmax,tmp1[j]); axmin=min(axmin,tmp1[j]);
aymax=max(aymax,tmp2[j]); aymin=min(aymin,tmp2[j]);
axmax=max(axmax,tmp3[j]); axmin=min(axmin,tmp3[j]);
aymax=max(aymax,tmp4[j]); aymin=min(aymin,tmp4[j]);
axmax=max(axmax,YSTN[j]); axmin=min(axmin,YSTN[j]);
aymax=max(aymax,ZSTN[j]); aymin=min(aymin,ZSTN[j]);
axmax=max(axmax,YGCN[j]); axmin=min(axmin,YGCN[j]);
aymax=max(aymax,ZGCN[j]); aymin=min(aymin,ZGCN[j]);
}
ax=axmax-axmin;
ay=aymax-aymin;
axmax=axmax+ax*0.02;
axmin=axmin-ax*0.02;
aymax=aymax+ay*0.10;
aymin=aymin-ay*0.02;
Ch2->Title->Text->SetText("Blade Axial Projection");
Ch2->BottomAxis->Title->Caption="Y(m)";
Ch2->LeftAxis->Title->Caption ="Z(m)" ;
Ch2->LeftAxis->Maximum=aymax;
Ch2->LeftAxis->Minimum=aymin;
Ch2->BottomAxis->Minimum=axmin;
Ch2->BottomAxis->Maximum=axmax;
Ch2->Legend->Visible=true;
Ch2->Legend->Color=clBtnFace;
Ch2->Legend->ColorWidth = 40;
Ch2->Legend->Frame->Visible = false;
Ch2->Legend->HorizMargin = 2;
Ch2->Legend->ResizeChart = false;
Ch2->Legend->ShadowSize = 0;
Ch2->Legend->TextStyle = ltsPlain;
Ch2->Legend->TopPos = 14;
Ch2->Legend->VertMargin = 2 ;
s_2[0] = new TLineSeries(this);
s_2[0]->Title = "LE";
s_2[0]->VertAxis = aLeftAxis;
s_2[0]->XValues->Order = loNone;
s_2[0]->YValues->Order = loNone;
s_2[0]->SeriesColor = clRed; //线的颜色
s_2[0]->Pointer->Brush->Color =clRed; //标注的填充颜色
s_2[0]->Pointer->InflateMargins = true;
s_2[0]->Pointer->Pen->Color = clRed; //标注的外圈颜色
s_2[0]->Pointer->Style = psRectangle;
s_2[0]->Pointer->HorizSize= 3;
s_2[0]->Pointer->VertSize = 3;
s_2[0]->Pointer->Visible = true;
for(i=0;i { s_2[0]->AddXY(tmp1[i],tmp2[i],"",clRed);
}
s_2[1] = new TLineSeries(this);
s_2[1]->Title = "STK";
s_2[1]->VertAxis = aLeftAxis;
s_2[1]->XValues->Order = loNone;
s_2[1]->YValues->Order = loNone;
s_2[1]->SeriesColor = clRed;
s_2[1]->Pointer->Brush->Color = clBtnFace;
s_2[1]->Pointer->InflateMargins = true;
s_2[1]->Pointer->Pen->Color = clRed;
s_2[1]->Pointer->Style = psCircle;
s_2[1]->Pointer->HorizSize= 4;
s_2[1]->Pointer->VertSize = 4;
s_2[1]->Pointer->Visible = true;
for(i=0;i { s_2[1]->AddXY(YSTN[i],ZSTN[i],"",clRed);
}
s_2[2] = new TLineSeries(this);
s_2[2]->Title = "CG";
s_2[2]->VertAxis = aLeftAxis;
s_2[2]->XValues->Order = loNone;
s_2[2]->YValues->Order = loNone;
s_2[2]->SeriesColor = clRed; //线的颜色
s_2[2]->Pointer->Brush->Color =clBtnFace; //标注的填充颜色
s_2[2]->Pointer->InflateMargins = true;
s_2[2]->Pointer->Pen->Color = clRed; //标注的外圈颜色
s_2[2]->Pointer->Style = psRectangle;
s_2[2]->Pointer->HorizSize= 3;
s_2[2]->Pointer->VertSize = 3;
s_2[2]->Pointer->Visible = true;
for(i=0;i { s_2[2]->AddXY(YGCN[i],ZGCN[i],"",clRed);
}
s_2[3] = new TLineSeries(this);
s_2[3]->Title = "TE";
s_2[3]->VertAxis = aLeftAxis;
s_2[3]->XValues->Order = loNone;
s_2[3]->YValues->Order = loNone;
s_2[3]->SeriesColor = clRed;
s_2[3]->Pointer->Brush->Color = clRed;
s_2[3]->Pointer->InflateMargins = true;
s_2[3]->Pointer->Pen->Color = clRed;
s_2[3]->Pointer->Style = psCircle;
s_2[3]->Pointer->HorizSize= 4;
s_2[3]->Pointer->VertSize = 4;
s_2[3]->Pointer->Visible = true;
for(i=0;i { s_2[3]->AddXY(tmp3[i],tmp4[i],"",clRed);
}
for(j=0;j<4;j++)
{ Ch2->AddSeries(s_2[j]);
}
axmax=-1000000.0; axmin= 1000000.0;
for(j=0;j { axmax=max(axmax,fabs(STAGGER[j])); axmin=min(axmin,fabs(STAGGER[j]));
}
ax=axmax-axmin;
axmax=axmax+ax*0.02; axmin=axmin-ax*0.02;
Memolist->Lines->Add("axmax="+FloatToStr(axmax));
Memolist->Lines->Add("axmin="+FloatToStr(axmin));
Ch3->Repaint();
Ch3->Title->Text->SetText("Stagger Angle Distribution");
Ch3->LeftAxis->Minimum=double(0.0);
Ch3->LeftAxis->Maximum=double(NLINES+2);
Ch3->LeftAxis->Title->Caption ="Radial Station No.J";
Ch3->BottomAxis->Automatic=false;
/* if(axmax>axmin) //此段是为了看是否仅是Ch3出问题了
{ Ch3->BottomAxis->Maximum=axmax;
Ch3->BottomAxis->Minimum=axmin;
}
Ch3->BottomAxis->Title->Caption="Stagger Angle(deg)";
Ch3->Legend->Visible=true;
Ch3->Legend->Color=clBtnFace;
Ch3->Legend->ColorWidth = 40;
Ch3->Legend->Frame->Visible = false;
Ch3->Legend->HorizMargin = 2;
Ch3->Legend->ResizeChart = false;
Ch3->Legend->ShadowSize = 0;
Ch3->Legend->TextStyle = ltsPlain;
Ch3->Legend->TopPos = 14;
Ch3->Legend->VertMargin = 2 ;
s_3[0] = new TLineSeries(this);
s_3[0]->Title ="Stagger Angle";
s_3[0]->VertAxis = aLeftAxis;
s_3[0]->XValues->Order = loNone;
s_3[0]->YValues->Order = loNone;
s_3[0]->SeriesColor = clRed; //线的颜色
s_3[0]->Pointer->Brush->Color =clBtnFace; //标注的填充颜色
s_3[0]->Pointer->InflateMargins = true;
s_3[0]->Pointer->Pen->Color = clRed;
s_3[0]->Pointer->Style = psCircle;
s_3[0]->Pointer->HorizSize= 4;
s_3[0]->Pointer->VertSize = 4;
s_3[0]->Pointer->Visible = true;
for(i=0;i { s_3[0]->AddXY(fabs(STAGGER[i]),i+1,"",clRed);
}
Ch3->AddSeries(s_3[0]); */
axmax=-1000000; axmin= 1000000;
for(j=0;j { axmax=max(axmax,tmp1[j]); axmin=min(axmin,tmp1[j]);
}
ax=axmax-axmin;
axmax=axmax+ax*0.02;
axmin=axmin-ax*0.02;
Ch4->Title->Text->SetText("Camber Angle Distribution");
Ch4->BottomAxis->Title->Caption="Camber Angle(deg)";
Ch4->LeftAxis->Title->Caption ="Radial Station No.J";
Ch4->LeftAxis->Maximum=double(NLINES+2);
Ch4->LeftAxis->Minimum=double(0.0);
Ch4->BottomAxis->Maximum=axmax;
Ch4->BottomAxis->Minimum=axmin;
Ch4->Legend->Visible=true;
Ch4->Legend->Color=clBtnFace;
Ch4->Legend->ColorWidth = 40;
Ch4->Legend->Frame->Visible = false;
Ch4->Legend->HorizMargin = 2;
Ch4->Legend->ResizeChart = false;
Ch4->Legend->ShadowSize = 0;
Ch4->Legend->TextStyle = ltsPlain;
Ch4->Legend->TopPos = 14;
Ch4->Legend->VertMargin = 2 ;
s_4[0] = new TLineSeries(this);
s_4[0]->Title = "Camber Angle";
s_4[0]->VertAxis = aLeftAxis;
s_4[0]->XValues->Order = loNone;
s_4[0]->YValues->Order = loNone;
s_4[0]->SeriesColor = clRed; //线的颜色
s_4[0]->Pointer->Brush->Color =clBtnFace; //标注的填充颜色
s_4[0]->Pointer->InflateMargins = true;
s_4[0]->Pointer->Pen->Color = clRed;
s_4[0]->Pointer->Style = psCircle;
s_4[0]->Pointer->HorizSize= 4;
s_4[0]->Pointer->VertSize = 4;
s_4[0]->Pointer->Visible = true;
for(i=0;i { s_4[0]->AddXY(tmp1[i],i+1,"",clRed);
}
Ch4->AddSeries(s_4[0]);
}
这个问题搞死我了, 真怀疑是C++B调用控件, 以及控件本身的问题