⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 labels.cpp

📁 Delphi Component - Chart Fx
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "labels.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ChartfxLib_TLB"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    int i;

    // Initializa data
    ChartFX1->OpenDataEx(COD_VALUES, 2, 10);
    for(i = 0; i < 10; i++) {
        ChartFX1->ValueEx[0][i] = 10 + (rand()*40.0)/RAND_MAX;
        ChartFX1->ValueEx[1][i] = 60 + (rand()*30.0)/RAND_MAX;
    }
    ChartFX1->CloseData(COD_VALUES);

    // Enable Y-Axis notification events for advanced customization
    ICfxAxisDisp pAxis;
    ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
    pAxis.Notify = TRUE;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int i;
    TFont *f;
    ICfxAxisDisp pAxis;
    TFontStyles nStyle;

    // assign each label
    for(i = 0; i < 10; i++)
        ChartFX1->Legend[i] = StringToOleStr(DateTimeToStr(Date() + i));

    // X Axis format
    f  = new TFont;

    ChartFX1->Axis->get_Item(AXIS_X,&pAxis);
    // set the text color of the x axis labels
    pAxis.TextColor = RGB(255, 255, 255);
    // set the style in which the labels should display
    pAxis.Style = (CfxAxisStyle) ((pAxis.Style | AS_2LEVELS | AS_CENTERED) & ~AS_LONGTICK);
    // set the font properties for the x axis labels
    SetOleFont(f, pAxis.Font);
    nStyle << (TFontStyle) (fsBold + fsItalic);
    f->Style = nStyle;
    f->Size = 10;
    f->Name = "Times New Roman";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    int i;
    TFont *f;
    char s[80];
    ICfxAxisDisp pAxis;
    TFontStyles nStyle;
    String sT;

    // the interval between 2 consecutive tickmarks is equal to 10
    ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
    pAxis.LabelValue = 10;

    // assign each label
    for(i = 0; i <= 10; i++) {
    	wsprintf(s,"Label %d",i);
        sT = s;
        pAxis.set_Label(i,StringToOleStr(sT));
    }

    f = new TFont;
    // set the text color of the y axis labels
    pAxis.TextColor = RGB(255, 255, 255);
    // set the font properties for the y axis labels
    SetOleFont(f, pAxis.Font);
    nStyle << fsItalic;
    f->Style = nStyle;
    f->Size = 10;
    f->Name = "Times New Roman";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
    ICfxSeriesDisp pSeries;

    // show the point labels for all series
    ChartFX1->PointLabels = True;

    // set the font properties for the point labels
    ChartFX1->PointLabelsFont->Name = "Courier New";
    ChartFX1->PointLabelsFont->Size = 8;

    // set the text color for the point labels
    ChartFX1->RGBFont[CHART_VALUESFT] = RGB(0, 0, 0);

    //set the angle of the point labels
    ChartFX1->Series->get_Item(0,&pSeries);
    //set the point labels to be aligned to the left of the marker
    pSeries.PointLabelAlign = LA_RIGHT | LA_TOP;
    pSeries.PointLabelAngle = -45;

    pSeries = NULL;
    ChartFX1->Series->get_Item(1,&pSeries);
    pSeries.PointLabelAngle = 45;
    // set the point labels to be aligned to the right of the marker
    pSeries.PointLabelAlign = LA_LEFT | LA_BASELINE;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
    TFont *f;
    TFontStyles nStyle;
    ICfxAxisDisp pAxis;

    // Y Axis title
    f = new TFont;
    ChartFX1->Axis->get_Item(AXIS_Y,&pAxis);
    pAxis.Title = L"Y Axis Title";
    pAxis.TitleColor = RGB(255, 255, 255);
    SetOleFont(f, pAxis.TitleFont);
    nStyle << (TFontStyle) (fsBold + fsItalic);
    f->Style = nStyle;
    f->Name = "Arial";
    f->Size = 12;

    // X Axis title
    pAxis = NULL;
    ChartFX1->Axis->get_Item(AXIS_X,&pAxis);
    pAxis.Title = L"X Axis Title";
    pAxis.TitleColor = RGB(255, 255, 255);
    SetOleFont(f, pAxis.TitleFont);
    nStyle << (TFontStyle) (fsBold + fsItalic);
    f->Style = nStyle;
    f->Name = "Arial";
    f->Size = 12;

    // Top title
    ChartFX1->Title[CHART_TOPTIT] = L"Labels and Titles";
    ChartFX1->Fonts[CHART_TOPTIT] = (CfxFontAttr) (CF_BOLD | CF_ITALIC | 16);
    ChartFX1->RGBFont[CHART_TOPTIT] = RGB(255, 255, 255);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
    // Custom Y-Axis labels. Make room
    if (CheckBox1->State == cbChecked)
        ChartFX1->LeftGap += 40;
    else
        ChartFX1->LeftGap -= 40;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
    ChartFX1->PointLabels = (CheckBox2->State == cbChecked);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ChartFX1GetAxisLabel(TObject *Sender, short nIndex,
      short *nRes)
{
    // Custom Y-Axis labels
    if (CheckBox1->State == cbChecked) {
        ChartFX1->HText = StringToOleStr(String("Custom ") + ChartFX1->HText);
        *nRes = 1;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartFX1GetPointLabel(TObject *Sender, short nType,
      long nIndex, short *nRes)
{
    // Custom point labels
    if (CheckBox2->State == cbChecked) {
        ChartFX1->HText = StringToOleStr(String("#") + ChartFX1->HText + String("#"));
        *nRes = 1;
    }
}
//---------------------------------------------------------------------------



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -