//---------------------------------------------------------------------------#include <vcl.h>#pragma hdrstop#include "SimpleChart.h"//---------------------------------------------------------------------------#pragma package(smart_init)// * Builder 10.x 版本之後毋庸下面四行// #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]; // declare Time arrays, which would keep real CPU timesdouble BubSortTime [10];double RandGenTime [10];//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender){ int i; Chart1->RemoveAllSeries(); // Remove all previous series Chart1->Title->Text->Clear(); // Clear chart chart title Chart1->Title->Text->Add("A sample chart"); Chart1->BottomAxis->Title->Caption = "data size"; // x-axis' title Chart1->LeftAxis->Title->Caption = "CPU time (sec.)"; // y-axis' title for (int i=0; i<5; i++) // acquire CPU time information for the three serieses { SelSortTime[i] = 10*(i+1)+rand()%10; // Just use random values here BubSortTime[i] = 12*(i+1)+rand()%12; RandGenTime[i] = 2*(i+1)+rand()%2; } Chart1->AddSeries( new TBarSeries (this) ); // create a new BAR series Chart1->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 4 Chart1->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 4 Chart1->AddSeries( new TLineSeries (this) ); // create a new LINE series Chart1->Series[2]->Title = "Data generation"; Chart1->Series[2]->AddArray( RandGenTime, 4 ); for (int i=0; i<3; i++) // Set marks visible { Chart1->Series[i]->Marks->Visible = true; Chart1->Series[i]->Marks->Style = smsValue; } /* ---- Another ways to create serieses // new series one by one TLineSeries * Series = new TLineSeries(Chart1); Chart1->AddSeries(Series);
TBarSeries * Series2 = new TBarSeries(Chart1); Chart1->AddSeries(Series2); // new series by loop for (i=1; i<=3; i++) { TLineSeries * Series = new TLineSeries(Chart1); Series->ParentChart = Chart1; Chart1->AddSeries(Series); } ---- */}//---------------------------------------------------------------------------