//先随机生成三条柱状图形对比,但是如果光是TChart是无法显示在intraweb网页上的,需要转成图片显示
void __fastcall TIWForm1::IWButton3Click(TObject *Sender)
{
Chart1->ClearChart();
Chart1->Align=alTop;
Chart1->Height=300; //高度
Chart1->View3D=false; //关掉3D显示
Chart1->Margins->Top=0;
Chart1->Margins->Bottom=0;
Chart1->Margins->Right=0;
Chart1->Margins->Left=10;
Chart1->MarginLeft=0;
Chart1->MarginBottom=0;
Chart1->MarginRight=2;
Chart1->MarginTop=0;
Chart1->Legend->Visible=true; //关掉图表右边的显示标签框
Chart1->LeftAxis->Increment=1; //左坐标的标尺单元长度
Chart1->MarginTop=5;
Chart1->Title->Caption =String("学生历史排名走势图");
//定义图表线条
TBarSeries* Series1;
Series1 = new TBarSeries(Chart1);
Series1->ParentChart=Chart1;
Chart1->AddSeries(Series1);
Chart1->SeriesList->Items[0]->Clear();
Chart1->SeriesList->Items[0]->Active=true;
Chart1->SeriesList->Items[0]->Visible=true;
Chart1->SeriesList->Items[0]->Pen->Visible=true;
Chart1->SeriesList->Items[0]->Pen->Width=1;
Chart1->SeriesList->Items[0]->Pen->Style=psSolid;
Chart1->SeriesList->Items[0]->Pen->Color= 6711039;
Chart1->SeriesList->Items[0]->Pen->SmallSpace=1;
Chart1->SeriesList->Items[0]->Pen->Show();
Chart1->SeriesList->Items[0]->SeriesColor=clRed;
TBarSeries* Series2;
Series2 = new TBarSeries(Chart1);
Series2->ParentChart=Chart1;
Chart1->AddSeries(Series2);
Chart1->SeriesList->Items[1]->Clear();
Chart1->SeriesList->Items[1]->Active=true;
Chart1->SeriesList->Items[1]->Visible=true;
Chart1->SeriesList->Items[1]->Pen->Visible=true;
Chart1->SeriesList->Items[1]->Pen->Width=1;
Chart1->SeriesList->Items[1]->Pen->Style=psSolid;
Chart1->SeriesList->Items[1]->Pen->Color= 6711039;
Chart1->SeriesList->Items[1]->Pen->SmallSpace=1;
Chart1->SeriesList->Items[1]->Pen->Show();
Chart1->SeriesList->Items[1]->SeriesColor=clBlue;
TBarSeries* Series3;
Series3 = new TBarSeries(Chart1);
Series3->ParentChart=Chart1;
Chart1->AddSeries(Series3);
srand((unsigned)time(NULL));
for(int i=1;i<50;i++)
{
int y= 1 + (int)50 * rand() / (RAND_MAX + 1);;
Chart1->SeriesList->Items[0]->AddXY(i,y,String(i),clRed);
y= 1 + (int)50 * rand() / (RAND_MAX + 1);;
Chart1->SeriesList->Items[1]->AddXY(i,y,String(i),clGreen);
y= 1 + (int)50 * rand() / (RAND_MAX + 1);;
Chart1->SeriesList->Items[2]->AddXY(i,y,String(i),clBlue);
}
Series1->Title ="2021年7月中考成绩";
Series2->Title="2022年3月金太阳联考";
Series3->Title="2022年4月稳派";
Series1->Marks->Visible=true;
Series2->Marks->Visible=true;
}
//然后将TChart 转换成图片,显示在网页上
void __fastcall TIWForm1::IWButton1Click(TObject *Sender)
{
TMetafile *xMetaFile;
TRect xRect;
TBitmap *xBitmap;
xBitmap= IWImage1->Picture->Bitmap;
xBitmap->Width = Chart1->Width;
xBitmap->Height =Chart1->Height;
IWImage1->Width=Chart1->Width;
IWImage1->Height=Chart1->Height;
xRect =Rect(0,0,Chart1->Width,Chart1->Height);
Chart1->BufferedDisplay=false;
xMetaFile=Chart1->TeeCreateMetafile(False,xRect);
//IWImage1->Picture->Bitmap->Canvas->Draw(0,0,xMetaFile);
xBitmap->Canvas->Draw(0,0,xMetaFile);
//FreeAndNil(xMetaFile);
}
//饼图的生成方法
void __fastcall TIWForm1::IWButton2Click(TObject *Sender)
{
Chart1->ClearChart();
TPieSeries * p_series=new TPieSeries (this);
p_series->AddXY (1, 50,"小李 ", clRed);
p_series->AddXY (1,25,"小刘",clGreen) ;
p_series->AddXY(1,25,"小梁",clYellow) ;
Chart1->AddSeries(p_series);
//Chart1->SaveToBitmapFile("tmp.bmp");
this->Refresh();
}