📄 buildergraph.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BuilderGraph.h"
#include <math.h>
#include <stdlib.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CWUIControlsLib_TLB"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
CWNumEditMin->Value = 20;
CWNumEditMax->Value = 84;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PlotWavClick(TObject *Sender)
{
Variant data(OPENARRAY(int,(0,99)),varDouble);
Variant vOptional;
int i;
for (i=0;i<100;i++)
data.PutElement(sin(i/5.0),i);
CWGraphProxy1->ClearData();
/*To use the default parameter, you must fill in a dummy parameter
Otherwise, create a Variant with the desired value*/
vOptional.vt = VT_ERROR;
vOptional.scode = (long)DISP_E_PARAMNOTFOUND;
CWGraphProxy1->PlotY(data,vOptional, vOptional, vOptional);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PlotRndClick(TObject *Sender)
{
Variant data(OPENARRAY(int,(0,99)),varDouble);
int i;
for (i=0;i<100;i++)
data.PutElement(rand()/10000.0,i);
CWGraphProxy1->ClearData();
Variant xFirst = 10;
Variant xInc = 0.5;
//To access a subobject, you must use Borland Builder's wrapper classes
//These are defined in the header file for each class. See CWUIControlsLib_TLB.h
CWPlotsDisp cwplots;
CWPlotDisp oneplot;
cwplots = CWGraphProxy1->Plots;
/*Before accessing a object in a collection, the object must be valid.
By default, there is only one plot object, at index = 1. You can add another in the
property pages for the graph control before using cwPlots.Item to access it.
You can also add plots at run-time using the following line*/
cwplots.Add();
Variant index = 2;
oneplot = cwplots.Item(index);
oneplot.PlotY(data, xFirst, xInc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PlotBothClick(TObject *Sender)
{
Variant data(OPENARRAY(int,(0,1,0,99)),varDouble);
int i;
for (i=0;i<100;i++){
data.PutElement(sin(i/5.0),0,i);
data.PutElement(rand()/10000.0,1,i);
}
CWGraphProxy1->ClearData();
Variant vOptional;
vOptional.vt = VT_ERROR;
vOptional.scode = (long)DISP_E_PARAMNOTFOUND;
CWGraphProxy1->PlotY(data,vOptional, vOptional, vOptional);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::xAxisClick(TObject *Sender)
{
CWAxesDisp cwaxes;
CWAxisDisp xaxis;
Variant index = 1;
OleVariant min;
OleVariant max;
min = CWNumEditMin->Value;
max = CWNumEditMax->Value;
cwaxes = CWGraphProxy1->Axes;
xaxis = cwaxes.Item(index);
xaxis.set_Minimum(min);
xaxis.set_Maximum(max);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AutoScaleClick(TObject *Sender)
{
Variant index = 1;
CWAxesDisp cwaxes;
CWAxisDisp xaxis;
cwaxes = CWGraphProxy1->Axes;
xaxis = cwaxes.Item(index);
xaxis.AutoScaleNow();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -