//---------------------------------------------------------------------------#include <vcl.h>#pragma hdrstop#include "SimpleChart.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma link "Chart"#pragma link "TeEngine"#pragma link "TeeProcs"#pragma link "Series"#pragma resource "*.dfm"TForm1 *Form1;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner){}double SelSortTime [10];double BubSortTime [10];double RandGenTime [10];//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender){ int i;Chart1->RemoveAllSeries(); // Remove all previous seriesChart1->Title->Text->Clear(); // Clear chart chart titleChart1->Title->Text->Add("A sample chart");Chart1->BottomAxis->Title->Caption = "data size"; // x-axis' titleChart1->LeftAxis->Title->Caption = "CPU time (sec.)"; // y-axis' titlefor (int i=0; i<5; i++) // acquire CPU time information for the three serieses{ SelSortTime[i] = 10*(i+1)+rand()%10;BubSortTime[i] = 12*(i+1)+rand()%12;RandGenTime[i] = 2*(i+1)+rand()%2;}Chart1->AddSeries( new TBarSeries (this) ); // create a new BAR seriesChart1->Series[0]->Title = "Selection Sort";Chart1->Series[0]->AddArray( SelSortTime, 4 ); // assign the values in SelSortTime onto the series one by one from 0 to 4Chart1->AddSeries( new TBarSeries (this) );Chart1->Series[1]->Title = "Bubble Sort";for (i=0; i<5; i++) Chart1->Series[1]->Add( BubSortTime[i], 10000*(i+1), clGreen );// assign the values in BubSortTime onto the series one by one from 0 to 4Chart1->AddSeries( new TLineSeries (this) ); // create a new LINE seriesChart1->Series[2]->Title = "Data generation";Chart1->Series[2]->AddArray( RandGenTime, 4 );
for (int i=0; i<3; i++){ Chart1->Series[i]->Marks->Visible = true;Chart1->Series[i]->Marks->Style = smsValue;}/*// new series one by oneTLineSeries * Series = new TLineSeries(Chart1);Chart1->AddSeries(Series);
TBarSeries * Series2 = new TBarSeries(Chart1);Chart1->AddSeries(Series2);// new series by loopfor (i=1; i<=3; i++){ TLineSeries * Series = new TLineSeries(Chart1);Series->ParentChart = Chart1;Chart1->AddSeries(Series);}*/}//---------------------------------------------------------------------------