如何根据已有的数据生成P-T曲线图?
有个现成的上位软件,每隔10秒记一次数据,有数据库,现在想根据已经接受到的数据生成一个曲线图,y轴是功率P,X轴是时间T,T是0到24小时,怎么弄,求高人指点
[解决办法]
没太多要求的话,就用TChart画就行,定义好横纵坐标,然后定义一个数据序列,把数据添进去就可以了
[解决办法]
从数据库中读出数据后,赋给Series
[解决办法]
//TDBChart 例子
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//以下是调用例子:
ADOTable1->Open();
//mypie("期初例数",ADOTable1,"nsort","bsum","temp1");
mypie("期初例数",ADOTable1,"nname","ssum","value"); //后面三参数为 表字段名
/*
USE [tempdb]
GO
---****** 对象: Table [dbo].[mz_table] 脚本日期: 05/30/2012 13:57:03 ******
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[mz_table](
[nname] [varchar](20) NOT NULL,
[ssum] [int] NOT NULL,
[value] [int] NOT NULL,
CONSTRAINT [PK_temp_mz_table] PRIMARY KEY CLUSTERED
(
[nname] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
insert into mz_table values('ma',1,1)
insert into mz_table values('mz',2,1)
insert into mz_table values('mt',2,2)
*/
}
//---------------------------------------
//以下是本人用DBChart动态建立series函数mypie()
//参数:
//t: 标题
//q :表名
//x :x轴列名 如:姓名字段(nname)
//y:Y轴列名 如:人数字段(ssum)
//xv x轴值列名
//饼形图
void __fastcall TForm1::mypie(AnsiString t,TADOTable *q,AnsiString x,AnsiString y,AnsiString xv)
{ //TChart 在Additional 页上 , TDBChart 看属性页上SeriesList 属性,或右键 选Edit Chart
//参数:
//t: 标题
//q :表名
//x :x轴列名 如:姓名字段(nname)
//y:Y轴列名 如:人数字段(ssum)
//xv x轴值列名
DBChart2->RemoveAllSeries();
DBChart2->Legend->LegendStyle=lsAuto;
DBChart2->AllowZoom=true;
DBChart2->AxisVisible=true;
TPieSeries *mypie=new TPieSeries(epImagePanel26); //need #include <Series.hpp>
//TPieSeries *mypie=new TPieSeries(this); //ok
//TLineSeries,TBarSeries,...
mypie->Clear();
mypie->Title=t;
DBChart2->Title->Text->SetText(t.c_str());
mypie->ParentChart=DBChart2;
mypie->DataSource=q;
mypie->XLabelsSource=x;
mypie->XValues->ValueSource=xv;
mypie->PieValues->ValueSource=y;
/*type TSeriesMarksStyle = (smsValue, smsPercent, smsLabel, smsLabelPercent, smsLabelValue, smsLegend, smsPercentTotal,
smsLabelPercentTotal, smsXValue, smsXY, smsSeriesTitle, smsPointIndex, smsPercentRelative);
*/
if(epComboBox10->ItemIndex!=9)
{
mypie->Marks->Visible=true;
mypie->Marks->Style=(TSeriesMarksStyle)(epComboBox10->ItemIndex+1);
}
else
mypie->Marks->Visible=false;
}