📄 passingdata.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "passingdata.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ChartfxLib_TLB"
#pragma link "OleCtrls"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
int i;
String s;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// Bars
ChartFX1->Gallery = BAR;
// Init data. 2 Series and 6 points means
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 6);
for (i = 0; i < 6; i++) {
ChartFX1->ValueEx[0][i] = 50 + rand()*50.0/RAND_MAX; // First Bar in the group
ChartFX1->ValueEx[1][i] = 50 + rand()*50.0/RAND_MAX; // Second Bar in the group
s = i+1;
ChartFX1->Legend[i] = StringToOleStr("Label " + s);
}
ChartFX1->CloseData(COD_VALUES);
// Set color for each series
ChartFX1->OpenDataEx(COD_COLORS, 2, 0);
ChartFX1->Color[0] = RGB(0, 255, 0);
ChartFX1->Color[1] = RGB(255, 0, 0);
ChartFX1->CloseData(COD_COLORS);
// Series legend
ChartFX1->SerLeg[0] = L"YES";
ChartFX1->SerLeg[1] = L"NO";
ChartFX1->SerLegBox = TRUE;
ChartFX1->SerLegBoxObj->set_Docked(TGFP_TOP);
}
//---------------------------------------------------------------------------
// From CHARTFX.H
#define CHART_HIDDEN 1.0e+308
void __fastcall TForm1::RadioButton2Click(TObject *Sender)
{
int i;
String s;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// Line/Step
ChartFX1->Gallery = STEP;
// Init data. Each series is a separate line
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 10);
for (i = 0; i < 10; i++) {
ChartFX1->ValueEx[0][i] = rand()*50.0/RAND_MAX; // First line
ChartFX1->ValueEx[1][i] = 50 + rand()*50.0/RAND_MAX; // Second line
s = i+1;
ChartFX1->Legend[i] = StringToOleStr("Label " + s);
}
ChartFX1->CloseData(COD_VALUES);
// Hide one point
ChartFX1->ValueEx[0][5] = CHART_HIDDEN;
// Set color for each line
ChartFX1->OpenDataEx(COD_COLORS, 2, 0);
ChartFX1->Color[0] = CHART_PALETTECOLOR | 44;
ChartFX1->Color[0] = CHART_PALETTECOLOR | 45;
ChartFX1->CloseData(COD_COLORS);
// Series legend
ChartFX1->SerLeg[0] = L"Yes";
ChartFX1->SerLeg[1] = L"No";
ChartFX1->SerLegBox = TRUE;
ChartFX1->SerLegBoxObj->set_Docked(TGFP_FLOAT);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton3Click(TObject *Sender)
{
double dFrom,dTo;
String s;
int i;
ICfxAxisDisp pAxis;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// Gantt chart
ChartFX1->Gallery = GANTT;
ChartFX1->RGB2DBk = RGB(255, 255, 255);
ChartFX1->RGBBk = RGB(255, 255, 255);
ChartFX1->AxesStyle = CAS_FLATFRAME;
// Y-Axis format
ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
pAxis.Grid = TRUE;
pAxis.GridColor = RGB(192, 192, 192);
v = "DMMM, yy";
pAxis.set_Format(v);
pAxis.Style = (pAxis.Style | AS_CENTERED | AS_INTERLACED) & ~AS_SHOWENDS;
pAxis.LabelAngle = 90;
pAxis.ResetScale();
pAxis.STEP_ = 30; // Monthly
pAxis.Style &= ~AS_SHOWENDS;
pAxis = NULL;
// x-Axis format
ChartFX1->Axis->get_Item(AXIS_X,&pAxis);
pAxis.Grid = TRUE;
pAxis.GridColor = RGB(192, 192, 192);
pAxis.Style |= AS_CENTERED;
pAxis = NULL;
// Set data and colors
// Starting point
ChartFX1->OpenDataEx(COD_INIVALUES | COD_REMOVE, 2, 8);
// Ending point point
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 8);
// Series legend
ChartFX1->SerLeg[0] = L"Projected"; // White
ChartFX1->SerLeg[1] = L"Actual"; // Black
ChartFX1->SerLegBox = TRUE;
// Bottom right
ChartFX1->SerLegBoxObj->set_Docked(TGFP_BOTTOM);
ChartFX1->SerLegBoxObj->set_BorderStyle(BBS_MONOLINE);
// Activities
ChartFX1->Title[CHART_TOPTIT] = L"My Project";
dFrom = StrToDate("01/01/98");
for (i = 0; i < 8; i++) {
// Projected
dFrom = dFrom + rand()*80.0/RAND_MAX;
dTo = dFrom + rand()*90.0/RAND_MAX;
ChartFX1->ValueEx[0][i] = dFrom;
ChartFX1->IniValueEx[0][i] = dTo;
// Actual
ChartFX1->ValueEx[1][i] = dFrom + rand()*30.0/RAND_MAX - 15;
ChartFX1->IniValueEx[1][i] = dTo + rand()*30.0/RAND_MAX - 15;
// Label
s = i+1;
ChartFX1->Legend[i] = StringToOleStr("Activity " + s);
}
// Adjust Min and Max
ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
pAxis.Min = StrToDate("01/01/98");
pAxis.Max = StrToDate("12/31/98");
ChartFX1->CloseData(COD_INIVALUES);
ChartFX1->CloseData(COD_VALUES);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton4Click(TObject *Sender)
{
double d;
int i;
String s;
ICfxAxisDisp pAxis;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// Financial
ChartFX1->Gallery = OPENHILOWCLOSE;
ChartFX1->Volume = 30; // Thin bars
// Init data
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 4, 30);
for (i = 0;i < 30; i++) {
d = 60 + rand()*40.0/RAND_MAX;
ChartFX1->ValueEx[OHLC_LOW][i] = d - rand()*60.0/RAND_MAX;
ChartFX1->ValueEx[OHLC_HIGH][i] = d;
ChartFX1->ValueEx[OHLC_OPEN][i] = d - rand()*20.0/RAND_MAX;
ChartFX1->ValueEx[OHLC_CLOSE][i] = d - rand()*20.0/RAND_MAX;
}
ChartFX1->CloseData(COD_VALUES);
// Format X-Axis
ChartFX1->Axis->get_Item(AXIS_X,&pAxis);
pAxis.set_Format(Variant(AF_DATE));
pAxis.Min = Now()+30;
pAxis.STEP_ = 7; // Weekly
pAxis.Style &= ~AS_SHOWENDS;
pAxis.FirstLabel = 1; // Show first day
// Init colors
ChartFX1->OpenDataEx(COD_COLORS, 3, 0);
ChartFX1->Color[0] = RGB(0, 255, 0); // Went down !
ChartFX1->Color[1] = RGB(255, 0, 0); // Went up !
ChartFX1->Color[2] = RGB(0, 0, 0);
ChartFX1->Color[3] = RGB(0, 0, 0);
ChartFX1->CloseData(COD_COLORS);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton5Click(TObject *Sender)
{
int i;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// Bubble chart
ChartFX1->Gallery = BUBBLE;
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 6);
for (i =0; i < 6; i++) {
ChartFX1->ValueEx[0][i] = 10 + rand()*(80.0)/RAND_MAX; // Bubble position (Y)
ChartFX1->ValueEx[1][i] = 60 + rand()*(40.0)/RAND_MAX; // Bubble size
}
ChartFX1->CloseData(COD_VALUES);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton6Click(TObject *Sender)
{
int i;
ICfxAxisDisp pAxis;
ICfxSeriesDisp pSeries;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// SCATTER (X/Y)
ChartFX1->Gallery = SCATTER;
ChartFX1->MarkerSize = 5;
// Set X/Y data
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 10);
ChartFX1->OpenDataEx(COD_XVALUES, 2, 10);
// Double scale
ChartFX1->Series->get_Item(0,&pSeries);
pSeries.YAxis = AXIS_Y;
pSeries = NULL;
ChartFX1->Series->get_Item(1,&pSeries);
pSeries.YAxis = AXIS_Y2;
pSeries.Gallery = LINES; // make second series a line
// Init data
for (i = 0; i < 10; i++) {
ChartFX1->ValueEx[0][i] = rand()*100.0/RAND_MAX;
ChartFX1->XValueEx[0][i] = i * i;
ChartFX1->ValueEx[1][i] = rand()*100000.0/RAND_MAX;
ChartFX1->XValueEx[1][i] = i * i + i;
}
ChartFX1->CloseData(COD_VALUES);
ChartFX1->CloseData(COD_XVALUES);
// Format X-Axis
ChartFX1->Axis->get_Item(AXIS_X,&pAxis);
pAxis.STEP_= 10;
pAxis.MinorStep = 5;
pAxis.Grid = TRUE;
pAxis = NULL;
// Format Primary Y-Axis
ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
pAxis.Min = 0;
pAxis.Max = 100;
pAxis = NULL;
// Format Secondary Y-Axis
ChartFX1->Axis->get_Item(AXIS_Y2,&pAxis);
pAxis.Min = 0;
pAxis.Max = 100000.0;
// Colors
ChartFX1->OpenDataEx(COD_COLORS, 2, 0);
ChartFX1->Color[0] = RGB(255, 0, 0);
ChartFX1->Color[1] = RGB(0, 255, 0);
ChartFX1->CloseData(COD_COLORS);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton7Click(TObject *Sender)
{
int i;
String s;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// PIE Chart
ChartFX1->Gallery = PIE;
//show point labels
ChartFX1->PointLabels = TRUE;
// Initialize data for 2 pies
// Each value represents a slice
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 10);
for (i = 0; i < 10; i++) {
ChartFX1->ValueEx[0][i] = 20 + rand()*100.0/RAND_MAX; // First PIE
ChartFX1->ValueEx[1][i] = 40 + rand()*100.0/RAND_MAX; // Second PIE
s = i+1;
ChartFX1->Legend[i] = StringToOleStr("Slice " + s);
}
ChartFX1->CloseData(COD_VALUES);
//Separate the same slice in both the pies
ChartFX1->SeparateSlice[2] = 25; // First pie 3rd slice
ChartFX1->SeparateSlice[12] = 25; // Second pie
//Assign the series legend (PIE TITLES)
ChartFX1->SerLeg[0] = L"Male";
ChartFX1->SerLeg[1] = L"Female";
//Assign colors to the slices (10 slices per pie)
ChartFX1->Palette = L"Spring";
ChartFX1->OpenDataEx(COD_COLORS, 10, 0);
for (i = 0; i < 10; i++)
ChartFX1->Color[i] = CHART_PALETTECOLOR | (rand()*40)/RAND_MAX;
ChartFX1->CloseData(COD_COLORS);
//to show the values legend box
ChartFX1->LegendBox = TRUE;
ChartFX1->LegendBoxObj->set_Docked(TGFP_BOTTOM);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton8Click(TObject *Sender)
{
int i;
String s;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// PYRAMID
ChartFX1->Gallery = PYRAMID;
// Init data. This is similar to PIE. Each series is a separate pyramid
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 5);
for (i = 0; i < 5; i++) {
ChartFX1->ValueEx[0][i] = 10 + rand()*100.0/RAND_MAX; // First pyramid
ChartFX1->ValueEx[1][i] = 10 + rand()*100.0/RAND_MAX; // Second pyramid
s = i+1;
ChartFX1->Legend[i] = StringToOleStr("Slice " + s);
}
ChartFX1->CloseData(COD_VALUES);
//Assign the series legend (PYRAMID TITLES)
ChartFX1->SerLeg[0] = L"Male";
ChartFX1->SerLeg[1] = L"Female";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton9Click(TObject *Sender)
{
int i;
String s;
ICfxAxisDisp pAxis;
// Start from original chart
Variant v;
v = "original.chd";
ChartFX1->Import(CHART_CFXOLEFILE, v);
// radar chart
ChartFX1->Gallery = RADAR;
ChartFX1->MarkerShape = MK_NONE;
// Init Y-Axis (Radius)
ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
pAxis.ResetScale();
pAxis.Decimals = 0;
pAxis = NULL;
// Init data. Each series is a line (color)
// The chart is drawn clockwise. The first point is at 12:00
// There are as many radius lines as points (60 in this case)
ChartFX1->OpenDataEx(COD_VALUES | COD_REMOVE, 2, 60);
for (i = 0; i < 60; i++) {
ChartFX1->ValueEx[0][i] = i; // Distance from center (first line)
ChartFX1->ValueEx[1][i] = i * 2; // Distance from center (second line)
s = i;
ChartFX1->Legend[i] = StringToOleStr(s);
}
ChartFX1->CloseData(COD_VALUES);
// Format X axis (around)
ChartFX1->Axis->get_Item(AXIS_X,&pAxis);
pAxis.STEP_ = 5; // A radius line every 45 points
pAxis.Grid = True;
pAxis.FirstLabel = 1; // First label at 12:00
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
ChartFX1->Chart3D = CheckBox1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
ChartFX1->Cluster = CheckBox1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Variant v;
// Save initial status
v = "original.chd";
ChartFX1->Export(CHART_CFXOLEFILE, v);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -