- 陶小凡
-
能不能帮上,我并不清楚。不过下面的是可用的
下面是一段代码(都是改自那个例子):
void __fastcall FormCreate(TObject *Sender);
void __fastcall BBtnZoomInClick(TObject *Sender);
void __fastcall BBtnZoomOutClick(TObject *Sender);
void __fastcall CheckBox3DClick(TObject *Sender);
void __fastcall BitBtnSaveClick(TObject *Sender);
void __fastcall BBtnPrintClick(TObject *Sender);
void __fastcall ADOQuery1AfterOpen(TDataSet *DataSet);
void __fastcall BitBtnUnZoomClick(TObject *Sender);
void __fastcall SBLeftClick(TObject *Sender);
void __fastcall SBRightClick(TObject *Sender);
void __fastcall SBUpClick(TObject *Sender);
void __fastcall SBDownClick(TObject *Sender);
void __fastcall ScrollBar1Change(TObject *Sender);
void __fastcall ScrollBar2Change(TObject *Sender);
void __fastcall ComBFirstChange(TObject *Sender);
void __fastcall ComBLastChange(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Chart1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall Series1AfterDrawValues(TObject *Sender);
void __fastcall Chart1Click(TObject *Sender);
private: // User declarations
int OldX;
int OldY;
double tmpX,tmpY;
AnsiString SQLstr, QueryWhere;
int Low, Hight;
TColor CrossHairColor;
TPenStyle CrossHairStyle;
int OldFirstPoint, OldLastPoint;
void ScrollAxis(TChartAxis* Axis, const double Percent);
void HorizScroll(const double Percent);
void VertScroll(const double Percent);
void ExeSQLStr(int start, int end);
void DrawCross(int ax, int ay);
bool SetValued = false;
//---------------------------------------------------------------------------
__fastcall TChart1Form::TChart1Form(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TChart1Form::ScrollAxis(TChartAxis* Axis, const double Percent)
{
double Amount = -((Axis->Maximum-Axis->Minimum)/(100.0/Percent));
Axis->SetMinMax(Axis->Minimum-Amount,Axis->Maximum-Amount);
}
//---------------------------------------------------------------------------
void TChart1Form::HorizScroll(const double Percent)
{
ScrollAxis(Chart1->TopAxis,Percent);
ScrollAxis(Chart1->BottomAxis,Percent);
}
//---------------------------------------------------------------------------
void TChart1Form::VertScroll(const double Percent)
{
ScrollAxis(Chart1->LeftAxis,Percent);
ScrollAxis(Chart1->RightAxis,Percent);
}
//---------------------------------------------------------------------------
void TChart1Form::ExeSQLStr(int start, int end)
{
QueryWhere = " WHERE No >= " + IntToStr(start) + " AND No <= " + IntToStr(end);
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
//QueryWhere = " WHERE No >= " + IntToStr(start) + " AND No <= " + IntToStr(end);
ADOQuery1->SQL->Add(SQLstr);
ADOQuery1->SQL->Add(QueryWhere);
ADOQuery1->Open();
//ADOQuery1->Parameters->Items[0]->Value = start;
//ADOQuery1->Parameters->Items[1]->Value = end;
ADOQuery1->Open();
}
//---------------------------------------------------------------------------
void TChart1Form::DrawCross(int ax, int ay)//画线
{
TColor tmp;
tmp = Chart1->BackColor;
if (tmp == clTeeColor)
tmp = clBtnFace;
Chart1->Canvas->Pen->Color = (TColor)(CrossHairColor ^ ColorToRGB(tmp));
Chart1->Canvas->Pen->Style = CrossHairStyle;
Chart1->Canvas->Pen->Mode = pmXor;
Chart1->Canvas->Pen->Width = 1;
Chart1->Canvas->MoveTo(ax,Chart1->ChartRect.Top-Chart1->Height3D);
Chart1->Canvas->LineTo(ax,Chart1->ChartRect.Bottom-Chart1->Height3D);
Chart1->Canvas->MoveTo(Chart1->ChartRect.Left+Chart1->Width3D,ay);
Chart1->Canvas->LineTo(Chart1->ChartRect.Right+Chart1->Width3D,ay);
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::FormCreate(TObject *Sender)
{
Form1->lgQQ_T->RecordCount;
Chart1->AnimatedZoom = true;
Chart1->AnimatedZoomSteps = 5;
ScrollBar1->Enabled = false;
ScrollBar2->Enabled = false;
OldX = -1;
CrossHairColor = clRed;
CrossHairStyle = psSolid;
Chart1->Cursor = crCross;
AnsiString TableName = Form1->lgQQ_T->TableName;
Low = 1;
Hight = Form1->lgQQ_T->RecordCount;
SQLstr += " SELECT No AS " 编号", sqrtT AS " T 的开方 ", log10QQ AS " lg[Q∞-Q(t)] "";
SQLstr += " FROM " + TableName;
QueryWhere = " WHERE No >= " + IntToStr(Low) + " AND No <= " + IntToStr(Hight);
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add(SQLstr);
ADOQuery1->SQL->Add(QueryWhere);
ADOQuery1->Open();
}
//-------------------------------------放大
void __fastcall TChart1Form::BBtnZoomInClick(TObject *Sender)
{
Chart1->ZoomPercent(105);
}
//---------------------------------------------------------缩小
void __fastcall TChart1Form::BBtnZoomOutClick(TObject *Sender)
{
Chart1->ZoomPercent(95);
}
//-------------------------------------------------三维
void __fastcall TChart1Form::CheckBox3DClick(TObject *Sender)
{
Chart1->View3D = CheckBox3D->Checked;
if (CheckBox3D->Checked)
{
ScrollBar1->Enabled = true;
ScrollBar2->Enabled = true;
if (dynamic_cast<TPieSeries*>(Chart1->Series[0]))
{
ScrollBar1->Position = Chart1->View3DOptions->Elevation;
}
else
{
ScrollBar1->Position = Chart1->View3DOptions->Rotation;
}
ScrollBar2->Position = Chart1->View3DOptions->Elevation;
}
else
{
ScrollBar1->Enabled = false;
ScrollBar2->Enabled = false;
}
}
//-----------------------------------------------保存图形到文件
void __fastcall TChart1Form::BitBtnSaveClick(TObject *Sender)
{
if (SavePictureDialog1->Execute())
{
Chart1->SaveToMetafile(SavePictureDialog1->FileName);
}
}
//------------------------------打印
void __fastcall TChart1Form::BBtnPrintClick(TObject *Sender)
{
int h, w;
Screen->Cursor = crHourGlass;
try
{
Printer()->BeginDoc();
try
{
Printer()->Canvas->Font->Name = "Arial";
Printer()->Canvas->Font->Size = 10;
Printer()->Canvas->Font->Style.Clear();
//Printer()->Canvas->TextOut(0,0,Edit1->Text);
h = Printer()->PageHeight; // <-- get page height
w = Printer()->PageWidth; // <-- get page width
// And now print the chart component
Chart1->PrintPartial( Rect(
10, // <-- 20% left margin
h / 3 , // <-- 33% top margin
w - 10, // <-- 20% right margin
h - (h / 5))); // <-- 20% bottom margin
Printer()->EndDoc(); // <-- end job and print !!
}
catch (...)
{
// just in case an error happens
Printer()->Abort();
Printer()->EndDoc();
throw; // <-- rethrow the exception !!!
}
}
__finally
{
Screen->Cursor = crDefault; // <-- restore cursor
}
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::ADOQuery1AfterOpen(TDataSet *DataSet)
{
if (!SetValued)
{
for (int i = 1; i <= ADOQuery1->RecordCount; i++)
{
ComBFirst->Items->Add(IntToStr(i));
ComBLast->Items->Add(IntToStr(i));
}
ComBFirst->ItemIndex = 0;
OldFirstPoint = ComBFirst->ItemIndex;
ComBLast->ItemIndex = ADOQuery1->RecordCount - 1 ;
OldLastPoint = ComBLast->ItemIndex;
SetValued = true;
}
}
//---------------------------重置缩放
void __fastcall TChart1Form::BitBtnUnZoomClick(TObject *Sender)
{
Chart1->UndoZoom();
}
//---------------------------------左右上下移动
void __fastcall TChart1Form::SBLeftClick(TObject *Sender)
{
HorizScroll(5);
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::SBRightClick(TObject *Sender)
{
HorizScroll(-5);
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::SBUpClick(TObject *Sender)
{
VertScroll(-5);
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::SBDownClick(TObject *Sender)
{
VertScroll(5);
}
//----------------------------------旋转三维图
void __fastcall TChart1Form::ScrollBar1Change(TObject *Sender)
{
if (CheckBox3D->Checked && ScrollBar1->Enabled)
{
Chart1->View3DOptions->Orthogonal = false;
}
if (dynamic_cast<TPieSeries*>(Chart1->Series[0]))
Chart1->View3DOptions->Elevation = ScrollBar1->Position;
else
Chart1->View3DOptions->Rotation = ScrollBar1->Position;
}
//----------------------------------------------------
void __fastcall TChart1Form::ScrollBar2Change(TObject *Sender)
{
if (CheckBox3D->Checked && ScrollBar2->Enabled)
{
Chart1->View3DOptions->Orthogonal = false;
Chart1->View3DOptions->Elevation = ScrollBar2->Position;
}
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::ComBFirstChange(TObject *Sender)
{
if (ComBFirst->ItemIndex < ComBLast->ItemIndex)
{
CheckBox3D->Checked = false;
Chart1->View3D = false;
Chart1->UndoZoom();
OldFirstPoint = ComBFirst->ItemIndex;
ExeSQLStr(ComBFirst->ItemIndex + 1, ComBLast->ItemIndex + 1);
}
else
{
MessageDlg("开始点大于或等于结束点,请重新选择!",
mtInformation, TMsgDlgButtons() << mbOK, 0);
ComBFirst->ItemIndex = OldFirstPoint;
}
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::ComBLastChange(TObject *Sender)
{
if (ComBFirst->ItemIndex < ComBLast->ItemIndex)
{
CheckBox3D->Checked = false;
Chart1->View3D = false;
Chart1->UndoZoom();
OldLastPoint = ComBLast->ItemIndex;
ExeSQLStr(ComBFirst->ItemIndex + 1, ComBLast->ItemIndex + 1);
}
else
{
MessageDlg("开始点大于或等于结束点,请重新选择!" ,
mtInformation, TMsgDlgButtons() << mbOK, 0);
ComBLast->ItemIndex = OldLastPoint;
}
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::FormClose(TObject *Sender,
TCloseAction &Action)
{
SetValued = false;
}
//-------------------------------画线
void __fastcall TChart1Form::Chart1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if (CheckBox1->Checked)
{
if (OldX != -1)
{
DrawCross(OldX,OldY); // draw old crosshair
OldX = -1;
}
if (PtInRect((RECT*)&Chart1->ChartRect, Point(X-Chart1->Width3D,Y+Chart1->Height3D)))
{
DrawCross(X,Y); // draw crosshair at current position
// store old position
OldX = X;
OldY = Y;
// set label text
Series1->GetCursorValues(tmpX,tmpY); // <-- get values under mouse cursor
Label7->Caption = Series1->GetVertAxis->LabelValue(tmpX)
+ " " + Series1->GetHorizAxis->LabelValue(tmpY);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TChart1Form::Series1AfterDrawValues(TObject *Sender)
{
OldX = -1; // Reset old mouse position
}
//------------------------定点
void __fastcall TChart1Form::Chart1Click(TObject *Sender)
{
if (CheckBox1->Checked)
{
CheckBox1->Checked = false;
EditX1->Text = FloatToStr(tmpX);
EditY1->Text = FloatToStr(tmpY);
- tt白
-
void __fastcall TChart1Form::Chart1Click(TObject *Sender)
{
if (CheckBox1->Checked)
{
CheckBox1->Checked = false;
EditX1->Text = FloatToStr(tmpX);
EditY1->Text = FloatToStr(tmpY);