分享
 
 
 

Chart 图表一例

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Chart组件的例子很少,让一些使用者用起来找不到头绪,现把我以前看过的一个比较好的例子拿出来与大家共同学习。

例图:

程序代码如下:

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "TeeBasic.h"

#include <stdlib.h>

#include <math.h>

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TDemoForm *DemoForm;

//---------------------------------------------------------------------------

__fastcall TDemoForm::TDemoForm(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

TChart* TDemoForm::TheChart()

{

String S = Notebook1->Pages->Strings[0];

TPage* page = static_cast<TPage*>(Notebook1->Pages->Objects[Notebook1->PageIndex]);

return dynamic_cast<TChart*>(page->Controls[0]);

}

void TDemoForm::HorizScroll(const double Percent)

{

ScrollAxis(TheChart()->TopAxis,Percent);

ScrollAxis(TheChart()->BottomAxis,Percent);

Button3->Enabled=true;

}

void TDemoForm::VertScroll(const double Percent)

{

ScrollAxis(TheChart()->LeftAxis,Percent);

ScrollAxis(TheChart()->RightAxis,Percent);

Button3->Enabled=true;

}

void TDemoForm::ScrollAxis(TChartAxis* Axis, const double Percent)

{

double Amount = -((Axis->Maximum-Axis->Minimum)/(100.0/Percent));

Axis->SetMinMax(Axis->Minimum-Amount,Axis->Maximum-Amount);

}

void __fastcall TDemoForm::ListBox1Click(TObject *Sender)

{

Notebook1->PageIndex=ListBox1->ItemIndex;

tmpTimes=-1;

TheChart()->AnimatedZoom=true;

TheChart()->AnimatedZoomSteps=4;

for (int t=0;t<TheChart()->SeriesCount();t++)

TheChart()->Series[t]->FillSampleValues(

TheChart()->Series[t]->NumSampleValues());

TheChart()->UndoZoom();

CheckBox1->Checked =TheChart()->View3D;

ScrollBar2->Enabled =TheChart()->View3D;

ScrollBar2->Position=TheChart()->Chart3DPercent;

if (dynamic_cast<TPieSeries*>(TheChart()->Series[0]))

ScrollBar3->Position=TheChart()->View3DOptions->Elevation;

else

ScrollBar3->Position=TheChart()->View3DOptions->Rotation;

ScrollBar4->Position=TheChart()->View3DOptions->Elevation;

ScrollBar3->Enabled=TheChart()->View3D;

ScrollBar4->Enabled=TheChart()->View3D;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::FormCreate(TObject *Sender)

{

tmpTimes=-1;

ScrollBar1->Position=Timer1->Interval;

ComboBox1->ItemIndex=0;

ComboBox2->ItemIndex=0;

ListBox1->ItemIndex =0;

ListBox1Click(this);

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::CheckBox1Click(TObject *Sender)

{

TheChart()->View3D=CheckBox1->Checked;

ScrollBar2->Enabled=TheChart()->View3D;

ScrollBar3->Enabled=TheChart()->View3D;

ScrollBar4->Enabled=TheChart()->View3D;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::CheckBox2Click(TObject *Sender)

{

Timer1->Enabled=CheckBox2->Checked;

ScrollBar1->Enabled=Timer1->Enabled;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::ScrollBar1Change(TObject *Sender)

{

Timer1->Interval=ScrollBar1->Position;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::Timer1Timer(TObject *Sender)

{

double tmpX;

switch (Notebook1->PageIndex) {

case 0 :

case 3 :

case 4 :

case 6 : {

for (int t=0;t<TheChart()->SeriesCount();t++) {

tmpX=TheChart()->Series[t]->XValues->Value[1]-

TheChart()->Series[t]->XValues->Value[0];

TheChart()->Series[t]->Delete(0);

TheChart()->Series[t]->AddXY(

TheChart()->Series[t]->XValues->Last()+tmpX,

TheChart()->Series[t]->YValues->Last()+random(100)-50,"",clTeeColor);

}

break;

}

case 1 :

case 2 :

case 8 : {

if (tmpTimes==-1) {

tmpSeries=random(TheChart()->SeriesCount());

tmpIndex =random(TheChart()->Series[tmpSeries]->Count());

tmpTimes =random(10);

tmpRandom=2*floor((random(50)-25.0) + .5);

}

if (tmpSeries != -1) {

if (Notebook1->PageIndex == 8) {

TBubbleSeries* s =

dynamic_cast<TBubbleSeries*>(TheChart()->Series[tmpSeries]);

tmpX=s->RadiusValues->Value[tmpIndex]+tmpRandom;

if (tmpX>=2) {

s->RadiusValues->Value[tmpIndex]=tmpX;

if (tmpRandom>0)

tmpX=s->XValues->Value[tmpIndex]+1;

else

tmpX=s->XValues->Value[tmpIndex]-1;

s->XValues->Value[tmpIndex]=tmpX;

if (random(10)<5)

tmpX=s->YValues->Value[tmpIndex]+50;

else

tmpX=s->YValues->Value[tmpIndex]-50;

s->YValues->Value[tmpIndex]=tmpX;

}

else tmpTimes=0;

}

else

TheChart()->Series[tmpSeries]->MandatoryValueList()->Value[tmpIndex] =

TheChart()->Series[tmpSeries]->MandatoryValueList()->Value[tmpIndex]+tmpRandom;

tmpTimes--;

TheChart()->Repaint();

}

break;

}

case 5: {

TPieSeries* s = dynamic_cast<TPieSeries*>(TheChart()->Series[0]);

s->Rotate(358);

break;

}

}

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::Button2Click(TObject *Sender)

{

Close();

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::BitBtn1Click(TObject *Sender)

{

TheChart()->ZoomPercent(120);

Button3->Enabled=true;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::BitBtn2Click(TObject *Sender)

{

TheChart()->ZoomPercent(80);

Button3->Enabled=true;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::SpeedButton1Click(TObject *Sender)

{

HorizScroll(10);

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::SpeedButton4Click(TObject *Sender)

{

HorizScroll(-10);

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::SpeedButton2Click(TObject *Sender)

{

VertScroll(-10);

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::SpeedButton3Click(TObject *Sender)

{

VertScroll(10);

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::CheckBox3Click(TObject *Sender)

{

TPieSeries* s = dynamic_cast<TPieSeries*>(TheChart()->Series[0]);

s->Circled=CheckBox3->Checked;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::ComboBox1Click(TObject *Sender)

{

TCustomBarSeries* s = dynamic_cast<TCustomBarSeries*>(TheChart()->Series[0]);

TComboBox* cb = dynamic_cast<TComboBox*>(Sender);

s->MultiBar=TMultiBar(cb->ItemIndex);

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::ScrollBar2Change(TObject *Sender)

{

TheChart()->Chart3DPercent=ScrollBar2->Position;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::Series28GetMarkText(TChartSeries *Sender,

int ValueIndex, AnsiString &MarkText)

{

if (ValueIndex==3)

MarkText="USA";

else if (ValueIndex==5)

MarkText="UK";

else if (ValueIndex==7)

MarkText="Germany";

else

MarkText="";

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::Button3Click(TObject *Sender)

{

TheChart()->UndoZoom();

Button3->Enabled=false;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::CheckBox4Click(TObject *Sender)

{

Series11->Stairs=CheckBox4->Checked;

Series12->Stairs=CheckBox4->Checked;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::FormShow(TObject *Sender)

{

Timer1->Enabled=true; // <-- start animation

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::ScrollBar3Change(TObject *Sender)

{

if (ScrollBar3->Enabled )

TheChart()->View3DOptions->Orthogonal=false;

if (dynamic_cast<TPieSeries*>(TheChart()->Series[0]))

TheChart()->View3DOptions->Elevation=ScrollBar3->Position;

else

TheChart()->View3DOptions->Rotation=ScrollBar3->Position;

}

//---------------------------------------------------------------------------

void __fastcall TDemoForm::ScrollBar4Change(TObject *Sender)

{

if (ScrollBar4->Enabled) {

TheChart()->View3DOptions->Orthogonal=false;

TheChart()->View3DOptions->Elevation=ScrollBar4->Position;

}

}

//---------------------------------------------------------------------------

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有