具体步骤:
一,拖控件,从控件组中拖出TChart控件.
二,双击TChart,按add添加所需数据组.
三,通过代码对其属性进行操作,修改.
四,录入数据点,生成图像.
以折线统计图为例,以下记录一些常用的接口及具体用法.
double * data ;
int N=2048 ; //动态成生数据组。
data = new double[N] ; //整个Y轴向量一次性添加。注意总点数为N-1。
Series1->Clear() ;
Series1->AddArray( data, N-1 ) ; //逐个数添加于X轴,Y轴为点号。
Series1->Clear() ;
for( int ii=0; ii<N; ii++ )
Series1->AddX( ii/0.2, "", clBlue ) ; //逐个数添加于Y轴,X轴为点号。
Series1->Clear() ;
for( int ii=0; ii<N; ii++ )
Series1->AddY( ii/0.2, "", clBlue ) ;
// Line类型的Series是逐个数据进行添加。 待所有的数据加入以后,从左到右边线,数据输入不分先后。
// Horizontal Line类型的Series是按数据添加顺序进行画图,逐点连线。
Series1->Clear() ;
for( int ii=0; ii<N; ii++ )
{
data[ii] = sin( 2*3.14*0.05*ii/22.0+1.2 ) ;
Series1->AddXY( ii/0.5, data[ii], "", clRed ) ;
}
for( int ii=0; ii<N; ii++ )
{
data[ii] = sin( 2*3.14*0.05*ii/40.0+1.0 ) ;
Series1->AddXY( ii/0.5, data[ii], "", clRed ) ;
}
//线型 线号
Series1->Pen->Width = 2 ;
Series1->Pen->Style = psDashDot ;
//OutLine->Visible = true 情况下有起作用。
//Series1->OutLine->Visible = true ;
Series1->LinePen->Color = clBlue ;
Series1->OutLine->Color = clBlue ;
Series1->Pen->Color = clBlue ;
// 线颜色
Series1->SeriesColor = clGreen ;
//轴名称,字体,颜色,字号。下划线.
Series1->GetVertAxis->Title->Caption = "Y坐标轴" ; //GetVertAxis是Y轴
Series1->GetVertAxis->Title->Font->Color = clRed ;
Series1->GetHorizAxis->Title->Caption = "X坐标轴" ; //GetHorizAxis是X轴
Series1->GetHorizAxis->Title->Font->Name = "华文行楷" ;
Series1->GetHorizAxis->Title->Font->Style=Series1->GetHorizAxis->Title->Font->Style<<fsUnderline ;//下划线,fsBold为加粗
Series1->GetHorizAxis->Title->Font->Size = 24 ;
Chart1->Title->Caption = "标题文字" ;
Chart1->Title->Font->Size = 36 ;
Chart1->Title->Font->Color = clGreen ;
Chart1->Title->Font->Style.Contains(fsUnderline) ;
Chart1->Title->Font->Name = "华文彩云" ;
Chart1->Title->Font->Name = "@华文彩云" ; //@的作用是90度旋转
//对数或性线坐标轴。
Chart1->Series[0]->GetVertAxis->Logarithmic = false ;
//坐标轴线型,线号,颜色。
Series1->GetHorizAxis->Axis->Style = psDash ;
Series1->GetHorizAxis->Axis->Width = 3 ;
Series1->GetHorizAxis->Axis->Color = clRed ;
//定制坐标轴范围。
//Series1->GetHorizAxis->SetMinMax( -N/3, N ) ;
//每一段的线颜色不同
//Series1->ColorEachPoint = false ;
Series1->ColorEachLine = true ;
//三维情况,线的深度
Series1->Depth = 50 ;
// 画线为阶梯形 ,正反阶梯形
Series1->Stairs = true ;
Series1->InvertedStairs = true ;
// mark显示
Series1->Marks->Visible = true ;
//数据点突出显示
Series1->Pointer->Visible = true ;
Series1->Pointer->Style = psCircle ;
Series1->Pointer->Color = clYellow ;
Series1->Pointer->Pen->Color = clYellow ;
// 隐藏坐标轴,连同它的网格线
Series1->GetVertAxis->Visible = false ;
Series1->GetHorizAxis->Visible = false ;
//标签角度
Series1->GetVertAxis->LabelsAngle = 0 ;
//标签间的间距像素值
Series1->GetVertAxis->LabelsSeparation = 200 ;
Series1->GetHorizAxis->Labels =false; //关闭标签显示 与网格是关联的。
//网格显示开关
Series1->GetVertAxis->Grid->Visible = false ;
Series1->GetHorizAxis->Grid->Visible = true ;
Series1->GetHorizAxis->Grid->Color = clRed ;
Series1->GetHorizAxis->Grid->Width = 1 ;
Series1->GetHorizAxis->Grid->Style = psSolid ;
//标签字号,颜色
Series1->GetHorizAxis->LabelsFont->Size = 6 ;
Series1->GetHorizAxis->LabelsFont->Color = clGray ;
Series1->GetHorizAxis->AxisValuesFormat = "#0.0" ;
Series1->GetHorizAxis->LabelsAngle = 45 ;
Series1->GetHorizAxis->AxisValuesFormat = "0.0e-0" ;
Series1->GetVertAxis->LabelsExponent = false ; //
// Tick (向坐标轴外) TickInner (向坐标轴内)
Series1->GetHorizAxis->TickLength = 10 ;
Series1->GetHorizAxis->TickInnerLength = 20 ;
Series1->GetHorizAxis->TicksInner->Visible = false ;
//坐标轴方向
Series1->GetHorizAxis->Inverted = true ;
// 标签间隔数值,正数,如果间隔过小,不足以显示标签,则自动采用更大的间隔。
Series1->GetHorizAxis->Increment = 500 ;
// 细网格 与细Ticker相关
Series1->GetHorizAxis->MinorTickCount = 4 ;
//细Ticker数,则平分段数为N+1.
Series1->GetHorizAxis->MinorGrid->Visible = true ;
// 细网格 默认颜色是背景色,需要改变才能显示出来。
Series1->GetHorizAxis->MinorGrid->Color = clBlue ;
Series1->GetHorizAxis->MinorGrid->Style = psDot ;
// 细Ticker
Series1->GetHorizAxis->MinorTicks->Visible = true ;
Series1->GetHorizAxis->MinorTickLength = 5 ;
摘录于百度文库,加了少许注释.以备后用.