关于Chart的其它问题

jlc 2004-09-10 12:45:30
本人在使用Chart时还遇到三个问题:
1)有没有简便的方法能够使X、Y坐标相关(dependent)? 我的目的是画一个二维几何图,只有坐标具有相同的标度时,图形才不失真。如果有程序段更好。
2)一张图上我需要画两套曲线,每套曲线的曲线总数目根据菜单输入(即事先不确定),如何做?
3)我试图在Chart图中人为添加字符(指明2)中每条曲线),但使用了下述两中方法后都不见效
a) ChartD->Canvas->Font->Height = -24;
ChartD->Canvas->Font->Color = clRed;
ChartD->Canvas->TextOutA(0.01,0.055,"text");
b) ChartD->Canvas->Font->Height = -24;
ChartD->Canvas->Font->Color = clRed;
ChartD->Canvas->TextOut(ChartD->ChartRect.Left+20,
ChartD->ChartRect.Bottom+20,"This is a text test");
其中b)方式输出"This is a text test"后瞬即被Chart覆盖掉。
谢谢关注。
...全文
278 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongwuzhao 2004-09-13
  • 打赏
  • 举报
回复
TLineSeries *s_pi[20];
TLineSeries *s_ef[20];

TLineSeries *s_pi[0] = new TLineSeries(this);
.
.
.
TLineSeries *s_pi[18] = new TLineSeries(this);
TLineSeries *s_pi[19] = new TLineSeries(this);


jlc 2004-09-13
  • 打赏
  • 举报
回复
Hi, 多谢HongwuZhao, 你说得对,太不认真,不过,说实话,虽然也编了点软件,但对C++B的一些语法仍云山雾罩。
多谢帮助!
jlc 2004-09-13
  • 打赏
  • 举报
回复
2)一张图上我需要画两套曲线,每套曲线的曲线总数目根据菜单输入(即事先不确定),如何做?我写的一段如下,但远未成功,各位看看用Chart如何解决这个问题?
agmx=-1000000;
agmn= 1000000;
apmx=-1000000;
apmn= 1000000;
aemx=-1000000;
aemn= 1000000;
for(i=0;i<NV;i++)
{ for(j=0;j<NEW[i];j++)
{ agmx=max(agmx,G[i][j]);
agmn=min(agmn,G[i][j]);
apmx=max(apmx,PI[i][j]);
apmn=min(apmn,PI[i][j]);
aemx=max(aemx,EF[i][j]);
aemn=min(aemn,EF[i][j]);
}
}

Memolist->Lines->Add("agmin="+FloatToStr(agmn));
Memolist->Lines->Add("agmax="+FloatToStr(agmx));
Memolist->Lines->Add("apmin="+FloatToStr(apmn));
Memolist->Lines->Add("apmax="+FloatToStr(apmx));
Memolist->Lines->Add("aemin="+FloatToStr(aemn));
Memolist->Lines->Add("aemax="+FloatToStr(aemx));

ag=agmx-agmn;
ap=apmx-apmn;
ae=aemx-aemn;
agmx=agmx+ag*0.02;
agmn=agmn-ag*0.02;
apmx=apmx+ap*0.02;
apmn=apmn-ap*0.02;
aemx=aemx+ae*0.02;
aemn=aemn-ae*0.02;

ChartP->BottomAxis->Maximum=agmx;
ChartP->BottomAxis->Minimum=agmn;
ChartP->LeftAxis->Maximum=apmx;
ChartP->LeftAxis->Minimum=apmn;
ChartP->RightAxis->Maximum=aemx;
ChartP->RightAxis->Minimum=aemn;

for(i=0;i<NV;i++)
{ ChartP->AddSeries(s_ef[i]);
for(j=0;j<NEW[i];j++)
{ s_ef[i]->XValues->Value[j]=G[i][j];
s_ef[i]->YValues->Value[j]=EF[i][j];
// s_ef[i]->AddXY(G[i][j],EF[i][j],"",clBlack);
}
ChartP->AddSeries(s_pi[i]);
for(j=0;j<NEW[i];j++)
{ s_pi[i]->XValues->Value[j]=G[i][j];
s_pi[i]->YValues->Value[j]=PI[i][j];
// s_pi[i]->AddXY(G[i][j],PI[i][j],"",clRed);
}
}
jlc 2004-09-13
  • 打赏
  • 举报
回复
求救第二个问题
hongwuzhao 2004-09-13
  • 打赏
  • 举报
回复
主要是不认真
-----------------------------------------------------------------------------
void __fastcall TMainform::BtPexecuteClick(TObject *Sender)
{ int i,j,iflag,K1,K2,K3,KK,NOM,NN;
float GR,TB,TNZ,U,GI[20],PII[20],ETI[20];
double ag,ap,ae;
// int GPmin,XPosmax,YPosmin,YPosmax;
FILE *stream;
TLineSeries *s_pi[20];
TLineSeries *s_ef[20];
iflag=0;
for(i=0;i<NV;i++)
{ if(SG_P->Cells[1][i+1]=="" )
{ iflag=1;
}
}
if(iflag==1)
{ ShowMessage("Please complete above inputs!");
}
else
{ ChartD->Visible=false;
ChartP->Visible=true;
ChartP->Align=alClient;
MemoOut->Visible=false;

for(i=0;i<NV;i++)
{ AN[i]=StrToFloat(SG_P->Cells[1][i+1]);
}
Memolist->Lines->Add("Performance analysis begins......!");
stream = fopen( "performance.plt", "w+" );

for(i=0;i<NV;i++)
{ GR=GMASS/PRIGV;
TB=288.;
K1=1;
K2=1;
K3=1;
TNZ=RPM*AN[i];
if(TNZ<=RPM)
{ NOM=0;
KK=1;
}
else
{ NOM=1;
KK=0;
}
HINSTANCE DLL_PERF=NULL;
DLL_PERF=LoadLibrary("PERFORMANCE.dll");
if(DLL_PERF)
{ F_PERF=(void(_stdcall *)(float *I_TNZ, float *I_GR, float *I_PITOT,
float *I_KPDCBKIN, float *I_RPM, float *I_LAM3IN,
float *I_TB, float *I_K, float *I_D2IN,
float *I_BTOUT,int *I_K1, int *I_K2, int *I_K3,
int *I_KK, int *I_NOM, float *I_RGAS,
float *I_PAI, float *I_DEG, float *O_U,
float *O_GI, float *O_PII, float *O_ETI, int *O_NN))
GetProcAddress(DLL_PERF,"PERF");
if(F_PERF)
{ F_PERF(&TNZ,&GR,&PITOT,&KPDCBKIN, &RPM,&LAM3IN,&TB,&K,&D2IN,&BTOUT,
&K1,&K2,&K3,&KK,&NOM,&RGAS,&PAI,°,&U,GI,PII,ETI,&NN);
}
else
{ ShowMessage("Error in performance analysis!");
}
}
else
ShowMessage("Unable to load DLL: PERFORMANCE.dll!");

fprintf(stream,"%s\n","zone i="+IntToStr(NN)+" f=point");
NEW[i]=NN;
for(j=0;j<NN;j++)
{ fprintf(stream,"%f %f\n",GI[j],PII[j]);
G[i][j]=GI[j];
PI[i][j]=PII[j];
EF[i][j]=ETI[j];
}
fprintf(stream,"%s\n","zone i="+IntToStr(NN)+" f=point");
for(j=0;j<NN;j++)
{ fprintf(stream,"%f %f\n",GI[j],ETI[j]);
}
}
fclose(stream);

agmx=-1000000;
agmn= 1000000;
apmx=-1000000;
apmn= 1000000;
aemx=-1000000;
aemn= 1000000;
for(i=0;i<NV;i++)
{ for(j=0;j<NEW[i];j++)
{ agmx=max(agmx,G[i][j]);
agmn=min(agmn,G[i][j]);
apmx=max(apmx,PI[i][j]);
apmn=min(apmn,PI[i][j]);
aemx=max(aemx,EF[i][j]);
aemn=min(aemn,EF[i][j]);
}
}

Memolist->Lines->Add("agmin="+FloatToStr(agmn));
Memolist->Lines->Add("agmax="+FloatToStr(agmx));
Memolist->Lines->Add("apmin="+FloatToStr(apmn));
Memolist->Lines->Add("apmax="+FloatToStr(apmx));
Memolist->Lines->Add("aemin="+FloatToStr(aemn));
Memolist->Lines->Add("aemax="+FloatToStr(aemx));

ag=agmx-agmn;
ap=apmx-apmn;
ae=aemx-aemn;
agmx=agmx+ag*0.02;
agmn=agmn-ag*0.02;
apmx=apmx+ap*0.02;
apmn=apmn-ap*0.02;
aemx=aemx+ae*0.02;
aemn=aemn-ae*0.02;

ChartP->BottomAxis->Maximum=agmx;
ChartP->BottomAxis->Minimum=agmn;
ChartP->LeftAxis->Maximum=apmx;
ChartP->LeftAxis->Minimum=apmn;
ChartP->RightAxis->Maximum=aemx;
ChartP->RightAxis->Minimum=aemn;

/*for(i=0;i<25;i++)
{ Hub->AddXY(XHUB[i],YHUB[i],"",clRed);
Tip->AddXY(XTIP[i],YTIP[i],"",clRed);
}
ChartP->Repaint(); */

for(i=0;i<NV;i++)
{ // ChartP->AddSeries(s_ef[i]);
s_ef[i] = new TLineSeries(this); //!!!!!!!!!!!!!!!!!!!!
s_ef[i]->Marks->ArrowLength = 8;
s_ef[i]->Marks->Visible = False;
s_ef[i]->SeriesColor = clBlue;
s_ef[i]->VertAxis = aRightAxis;
s_ef[i]->LinePen->Color = clGreen;
s_ef[i]->XValues->DateTime = False;
s_ef[i]->XValues->Name = 'X';
s_ef[i]->XValues->Multiplier = 1;
s_ef[i]->XValues->Order = loNone;
s_ef[i]->YValues->DateTime = False;
s_ef[i]->YValues->Name = 'Y';
s_ef[i]->YValues->Multiplier = 1;
s_ef[i]->YValues->Order = loNone;
for(j=0;j<NEW[i];j++)
{ //s_ef[i]->XValues->Value[j]=G[i][j]; //!!!!!!!!!!!!!!
//s_ef[i]->YValues->Value[j]=EF[i][j];//!!!!!!!!!!!!!!!
s_ef[i]->AddXY(G[i][j],EF[i][j],"",clBlack);
}
ChartP->AddSeries(s_ef[i]); // !!!!!!!!!!!!!!!!!!!!!!

s_pi[i] = new TLineSeries(this); //!!!!!!!!!!!!!!!!!!!!!!!!!
s_pi[i]->Marks->ArrowLength = 8;
s_pi[i]->Marks->Visible = False;
s_pi[i]->SeriesColor = clRed;
s_pi[i]->VertAxis = aLeftAxis;
s_pi[i]->LinePen->Color = clBlue;
s_pi[i]->XValues->DateTime = False;
s_pi[i]->XValues->Name = 'X';
s_pi[i]->XValues->Multiplier = 1;
s_pi[i]->XValues->Order = loNone;
s_pi[i]->YValues->DateTime = False;
s_pi[i]->YValues->Name = 'Y';
s_pi[i]->YValues->Multiplier = 1;
s_pi[i]->YValues->Order = loNone;
ChartP->AddSeries(s_pi[i]); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for(j=0;j<NEW[i];j++)
{ //s_pi[i]->XValues->Value[j]=G[i][j]; //!!!!!!!!!!!!!
//s_pi[i]->YValues->Value[j]=PI[i][j]; //!!!!!!!!!!!!
s_pi[i]->AddXY(G[i][j],PI[i][j],"",clRed); //!!!!!!!!!!
}
}
ChartP->Repaint();
Memolist->Lines->Add("Performance analysis finished!");
}
}


jlc 2004-09-13
  • 打赏
  • 举报
回复
还是不行,请帮看一下整个程序段:
void __fastcall TMainform::BtPexecuteClick(TObject *Sender)
{ int i,j,iflag,K1,K2,K3,KK,NOM,NN;
float GR,TB,TNZ,U,GI[20],PII[20],ETI[20];
double ag,ap,ae;
// int GPmin,XPosmax,YPosmin,YPosmax;
FILE *stream;
TLineSeries *s_pi[20];
TLineSeries *s_ef[20];
iflag=0;
for(i=0;i<NV;i++)
{ if(SG_P->Cells[1][i+1]=="" )
{ iflag=1;
}
}
if(iflag==1)
{ ShowMessage("Please complete above inputs!");
}
else
{ ChartD->Visible=false;
ChartP->Visible=true;
ChartP->Align=alClient;
MemoOut->Visible=false;

for(i=0;i<NV;i++)
{ AN[i]=StrToFloat(SG_P->Cells[1][i+1]);
}
Memolist->Lines->Add("Performance analysis begins......!");
stream = fopen( "performance.plt", "w+" );

for(i=0;i<NV;i++)
{ GR=GMASS/PRIGV;
TB=288.;
K1=1;
K2=1;
K3=1;
TNZ=RPM*AN[i];
if(TNZ<=RPM)
{ NOM=0;
KK=1;
}
else
{ NOM=1;
KK=0;
}
HINSTANCE DLL_PERF=NULL;
DLL_PERF=LoadLibrary("PERFORMANCE.dll");
if(DLL_PERF)
{ F_PERF=(void(_stdcall *)(float *I_TNZ, float *I_GR, float *I_PITOT,
float *I_KPDCBKIN, float *I_RPM, float *I_LAM3IN,
float *I_TB, float *I_K, float *I_D2IN,
float *I_BTOUT,int *I_K1, int *I_K2, int *I_K3,
int *I_KK, int *I_NOM, float *I_RGAS,
float *I_PAI, float *I_DEG, float *O_U,
float *O_GI, float *O_PII, float *O_ETI, int *O_NN))
GetProcAddress(DLL_PERF,"PERF");
if(F_PERF)
{ F_PERF(&TNZ,&GR,&PITOT,&KPDCBKIN, &RPM,&LAM3IN,&TB,&K,&D2IN,&BTOUT,
&K1,&K2,&K3,&KK,&NOM,&RGAS,&PAI,°,&U,GI,PII,ETI,&NN);
}
else
{ ShowMessage("Error in performance analysis!");
}
}
else
ShowMessage("Unable to load DLL: PERFORMANCE.dll!");

fprintf(stream,"%s\n","zone i="+IntToStr(NN)+" f=point");
NEW[i]=NN;
for(j=0;j<NN;j++)
{ fprintf(stream,"%f %f\n",GI[j],PII[j]);
G[i][j]=GI[j];
PI[i][j]=PII[j];
EF[i][j]=ETI[j];
}
fprintf(stream,"%s\n","zone i="+IntToStr(NN)+" f=point");
for(j=0;j<NN;j++)
{ fprintf(stream,"%f %f\n",GI[j],ETI[j]);
}
}
fclose(stream);

agmx=-1000000;
agmn= 1000000;
apmx=-1000000;
apmn= 1000000;
aemx=-1000000;
aemn= 1000000;
for(i=0;i<NV;i++)
{ for(j=0;j<NEW[i];j++)
{ agmx=max(agmx,G[i][j]);
agmn=min(agmn,G[i][j]);
apmx=max(apmx,PI[i][j]);
apmn=min(apmn,PI[i][j]);
aemx=max(aemx,EF[i][j]);
aemn=min(aemn,EF[i][j]);
}
}

Memolist->Lines->Add("agmin="+FloatToStr(agmn));
Memolist->Lines->Add("agmax="+FloatToStr(agmx));
Memolist->Lines->Add("apmin="+FloatToStr(apmn));
Memolist->Lines->Add("apmax="+FloatToStr(apmx));
Memolist->Lines->Add("aemin="+FloatToStr(aemn));
Memolist->Lines->Add("aemax="+FloatToStr(aemx));

ag=agmx-agmn;
ap=apmx-apmn;
ae=aemx-aemn;
agmx=agmx+ag*0.02;
agmn=agmn-ag*0.02;
apmx=apmx+ap*0.02;
apmn=apmn-ap*0.02;
aemx=aemx+ae*0.02;
aemn=aemn-ae*0.02;

ChartP->BottomAxis->Maximum=agmx;
ChartP->BottomAxis->Minimum=agmn;
ChartP->LeftAxis->Maximum=apmx;
ChartP->LeftAxis->Minimum=apmn;
ChartP->RightAxis->Maximum=aemx;
ChartP->RightAxis->Minimum=aemn;

/*for(i=0;i<25;i++)
{ Hub->AddXY(XHUB[i],YHUB[i],"",clRed);
Tip->AddXY(XTIP[i],YTIP[i],"",clRed);
}
ChartP->Repaint(); */

for(i=0;i<NV;i++)
{ // ChartP->AddSeries(s_ef[i]);
TLineSeries *s_ef[i] = new TLineSeries(this);
s_ef[i]->Marks->ArrowLength = 8;
s_ef[i]->Marks->Visible = False;
s_ef[i]->SeriesColor = clBlue;
s_ef[i]->VertAxis = aRightAxis;
s_ef[i]->LinePen->Color = clGreen;
s_ef[i]->XValues->DateTime = False;
s_ef[i]->XValues->Name = 'X';
s_ef[i]->XValues->Multiplier = 1;
s_ef[i]->XValues->Order = loNone;
s_ef[i]->YValues->DateTime = False;
s_ef[i]->YValues->Name = 'Y';
s_ef[i]->YValues->Multiplier = 1;
s_ef[i]->YValues->Order = loNone;
for(j=0;j<NEW[i];j++)
{ s_ef[i]->XValues->Value[j]=G[i][j];
s_ef[i]->YValues->Value[j]=EF[i][j];
// s_ef[i]->AddXY(G[i][j],EF[i][j],"",clBlack);
}
// ChartP->AddSeries(s_pi[i]);
TLineSeries *s_pi[i] = new TLineSeries(this);
s_pi[i]->Marks->ArrowLength = 8;
s_pi[i]->Marks->Visible = False;
s_pi[i]->SeriesColor = clRed;
s_pi[i]->VertAxis = aLeftAxis;
s_pi[i]->LinePen->Color = clBlue;
s_pi[i]->XValues->DateTime = False;
s_pi[i]->XValues->Name = 'X';
s_pi[i]->XValues->Multiplier = 1;
s_pi[i]->XValues->Order = loNone;
s_pi[i]->YValues->DateTime = False;
s_pi[i]->YValues->Name = 'Y';
s_pi[i]->YValues->Multiplier = 1;
s_pi[i]->YValues->Order = loNone;
// ChartP->AddSeries(s_pi[i]);
for(j=0;j<NEW[i];j++)
{ s_pi[i]->XValues->Value[j]=G[i][j];
s_pi[i]->YValues->Value[j]=PI[i][j];
// s_pi[i]->AddXY(G[i][j],PI[i][j],"",clRed);
}
}
ChartP->Repaint();
Memolist->Lines->Add("Performance analysis finished!");
}
}
上述错误信息为
[C++ Error] ccdp_main.cpp(633): E2313 Constant expression required
[C++ Error] ccdp_main.cpp(633): E2034 Cannot convert 'TLineSeries *' to 'TLineSeries *[1]'
[C++ Error] ccdp_main.cpp(653): E2313 Constant expression required
[C++ Error] ccdp_main.cpp(653): E2034 Cannot convert 'TLineSeries *' to 'TLineSeries *[1]'
[C++ Warning] ccdp_main.cpp(843): W8006 Initializing TFloatFormat with TStringFloatFormat
[C++ Warning] ccdp_main.cpp(844): W8006 Initializing TFloatFormat with TStringFloatFormat
[

jlc 2004-09-12
  • 打赏
  • 举报
回复
HongWuzhao,你好,谢谢答复,但仍有问题
第一个问题实质是在什么过程中设置最大最小值的问题,你看我编的一段,基本实现了功能,但调用...Axis->Maximum两次,而且必须Repaint()两次,如果不是这样,那么在开始时,Axis->Maximum均为0,程序溢出。我的程序段如下:
axmx=-1000000;
axmn= 1000000;
aymx=-1000000;
aymn= 1000000;
for(i=0;i<25;i++)
{ axmx=max(axmx,XHUB[i]);
axmn=min(axmn,XHUB[i]);
aymx=max(aymx,YHUB[i]);
aymn=min(aymn,YHUB[i]);
}
for(i=0;i<25;i++)
{ axmx=max(axmx,XTIP[i]);
axmn=min(axmn,XTIP[i]);
aymx=max(aymx,YTIP[i]);
aymn=min(aymn,YTIP[i]);
}
Memolist->Lines->Add("axmin="+FloatToStr(axmn));
Memolist->Lines->Add("axmax="+FloatToStr(axmx));
Memolist->Lines->Add("aymin="+FloatToStr(aymn));
Memolist->Lines->Add("aymax="+FloatToStr(aymx));
ax=axmx-axmn; //求数据最大、最小
ay=aymx-aymn;
axmx=axmx+ax*0.02;//给定轴最大最小坐标
axmn=axmn-ax*0.02;
aymx=aymx+ay*0.02;
aymn=aymn-ay*0.02;

ChartD->LeftAxis->Maximum=aymx;
ChartD->LeftAxis->Minimum=aymn;
ChartD->BottomAxis->Maximum=axmx;
ChartD->BottomAxis->Minimum=axmn;
for(i=0;i<25;i++)
{ Hub->AddXY(XHUB[i],YHUB[i],"",clRed);
Tip->AddXY(XTIP[i],YTIP[i],"",clRed);
}
ChartD->Repaint(); //Repaint 使得下面几行可以计算出非零值。

XPosmin = ChartD->BottomAxis->CalcXPosValue(axmn);
XPosmax = ChartD->BottomAxis->CalcXPosValue(axmx);
YPosmin = ChartD->LeftAxis->CalcYPosValue(aymn);
YPosmax = ChartD->LeftAxis->CalcYPosValue(aymx);

ax=(axmx-axmn)/(XPosmax-XPosmin);
ay=(aymx-aymn)/(YPosmin-YPosmax);
if(ax>ay)
{ ChartD->LeftAxis->Maximum=aymx+(ax-ay)*(YPosmin-YPosmax)/2.;
ChartD->LeftAxis->Minimum=aymn-(ax-ay)*(YPosmin-YPosmax)/2.;
ChartD->BottomAxis->Maximum=axmx;
ChartD->BottomAxis->Minimum=axmn;
}
else
{ ChartD->BottomAxis->Maximum=axmx+(ay-ax)*(XPosmax-XPosmin)/2.;
ChartD->BottomAxis->Minimum=axmn-(ay-ax)*(XPosmax-XPosmin)/2.;
ChartD->LeftAxis->Maximum=aymx;
ChartD->LeftAxis->Minimum=aymn;
}
ChartD->Repaint();

关于第二个问题,我还是不会用,你所指设置系列格式指的是哪些?我如下用为什么不成
TLineSeries *s_pi[20];
TLineSeries *s_ef[20];
for(i=0;i<NV;i++)
{ 此处有个子程序,每次给出GI[j],PII[j],ETI[j],j=1,NN
for(j=0;j<NN;j++)
{ ChartP->AddSeries(s_ef[j]);//有无此行均不行!
s_ef[j]->AddXY(GI[j],ETI[j],"",clBlack);
}
for(j=0;j<NN;j++)
{ ChartP->AddSeries(s_pi[j]);
s_pi[j]->AddXY(GI[j],PII[j],"",clRed);
}
}


hongwuzhao 2004-09-11
  • 打赏
  • 举报
回复
没有看太明白。
1)
a)this->Chart1->BottomAxis->Automatic = false;
b)手工设置坐标轴的
this->Chart1->BottomAxis->Minimum = ?;
this->Chart1->BottomAxis->Maximum = ?

2)根据需要动态添加
TLineSeries * MyTLineSeries = new TLineSeries(Chart1);
。。。。。设置系列格式
this->Chart1->AddSeries(MyTLineSeries);

3)在Chart1AfterDraw中写文本





jlc 2004-09-11
  • 打赏
  • 举报
回复
没解答么?

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧