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

📄 cfxlabels.cpp

📁 Delphi Component - Chart Fx
💻 CPP
字号:
// CfxLabels.cpp : implementation file
//

#include "stdafx.h"
#include "cfx98.h"
#include "CfxLabels.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCfxLabels dialog


CCfxLabels::CCfxLabels(CWnd* pParent /*=NULL*/)
	: CDialog(CCfxLabels::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCfxLabels)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CCfxLabels::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCfxLabels)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	// ***CFX***
	// Do not use class wizard to generate these. It will cause the generation of unecesary classes
	DDX_Control(pDX, IDC_CHART1, m_ChartFX);
	if (!pDX->m_bSaveAndValidate) // Link Chart FX pointer to control window
		m_pChartFX = m_ChartFX.GetControlUnknown();
	// ***CFX***

}


BEGIN_MESSAGE_MAP(CCfxLabels, CDialog)
	//{{AFX_MSG_MAP(CCfxLabels)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_XLABELS, OnXlabels)
	ON_BN_CLICKED(IDC_YLABELS, OnYlabels)
	ON_BN_CLICKED(IDC_POINTLABELS, OnPointlabels)
	ON_BN_CLICKED(IDC_TITLES, OnTitles)
	ON_BN_CLICKED(IDC_CUSYLABELS, OnCusylabels)
	ON_BN_CLICKED(IDC_CUSPOINTLABELS, OnCuspointlabels)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCfxLabels message handlers

void CCfxLabels::OnDestroy() 
{
	m_pChartFX = NULL;

	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

void CCfxLabels::OnXlabels() 
{
	// TODO: Add your control notification handler code here

	    
	int i;
	COleDateTime d;
	ICfxAxisPtr pAxis;
	SYSTEMTIME t;
	char buffer[50];

	t.wYear = 1998;
	t.wMonth = 8;
	t.wDay = 5;

    
    //assign each label
    for (i=0;i<10; i++) {
		t.wDay = t.wDay + 1;
		GetDateFormat(NULL, NULL, &t, NULL, buffer,50); 
        m_pChartFX->Legend[i] = buffer;
	}
    
        
    pAxis = m_pChartFX->Axis->Item[AXIS_X];

    //set the text color of the x and y axis labels
    pAxis->TextColor = RGB(255, 255, 255);
    //set the font properties for the x axis labels
	pAxis->FontMask = (CfxFontAttr) (pAxis->FontMask | CF_TIMESNEWR | CF_ITALIC | 10);
    //set the style in which the labels should display
    pAxis->Style = (CfxAxisStyle) ((pAxis->Style | AS_2LEVELS | AS_CENTERED) & ~AS_LONGTICK);
	
        
  
    
    

	
}

void CCfxLabels::OnYlabels() 
{
	// TODO: Add your control notification handler code here

    int i,j;
	ICfxAxisPtr pAxis;
	char buffer[20], s[] = "label ";
    
    m_pChartFX->LeftGap = 80;

	pAxis = m_pChartFX->Axis->Item[AXIS_Y];

    //the interval between 2 consecutive tickmarks is equal to 10
    pAxis->LabelValue = 10;

	j = sprintf(buffer, "%s", s);
    //assign each label
    for (i=0;i<10;i++) {
		itoa(i, buffer+j, 10);
	    pAxis->Label[i] = buffer;
    }
    
    //set the text color of the y axis labels
    pAxis->TextColor = RGB(255, 255, 255);
    //set the font properties for the y axis labels
	pAxis->FontMask = (CfxFontAttr) (pAxis->FontMask | CF_TIMESNEWR | CF_ITALIC | 10);
        
}

void CCfxLabels::OnPointlabels() 
{
	// TODO: Add your control notification handler code here

    //show the point labels for all series
    m_pChartFX->PointLabels = TRUE;
    
            
    //set the font properties for the point labels
    m_pChartFX->Fonts[(CfxFont) CHART_VALUESFT] = (CfxFontAttr) (CF_COURIERNEW | 8);
    
    //set the text color for the point labels
    m_pChartFX->RGBFont[CHART_VALUESFT] = RGB(0, 0, 0);
    
    //set the angle of the point labels
    m_pChartFX->Series->Item[0]->PointLabelAngle = -45;
    m_pChartFX->Series->Item[1]->PointLabelAngle = 45;
    
    //set the point labels to be aligned to the left of the marker
    m_pChartFX->Series->Item[0]->PointLabelAlign = (CfxAlign) (LA_RIGHT | LA_TOP);
    
    //set the point labels to be aligned to the right of the marker
    m_pChartFX->Series->Item[1]->PointLabelAlign = (CfxAlign) (LA_LEFT | LA_BASELINE);

	
}

void CCfxLabels::OnTitles() 
{
	// TODO: Add your control notification handler code here

	ICfxAxisPtr pAxis;

	pAxis = m_pChartFX->Axis->Item[AXIS_Y];

    
    pAxis->Title = "Y Axis Title";
    pAxis->TitleColor = RGB(255, 255, 255);
	m_pChartFX->Fonts[CHART_LEFTFT] = (CfxFontAttr) (CF_ARIAL | CF_BOLD | CF_ITALIC | 12);

    pAxis = m_pChartFX->Axis->Item[AXIS_X];

    
    pAxis->Title = "X Axis Title";
    pAxis->TitleColor = RGB(255, 255, 255);
        
	m_pChartFX->Fonts[CHART_BOTTOMFT] = (CfxFontAttr) (CF_ARIAL | CF_BOLD | CF_ITALIC | 12);
	
    m_pChartFX->TopGap = 50;
    m_pChartFX->Title[CHART_TOPTIT] = "Labels and Titles";
    m_pChartFX->Fonts[(CfxFont) CHART_TOPTIT] = (CfxFontAttr) (CF_BOLD | CF_ITALIC | 16);
    m_pChartFX->RGBFont[(CfxFont) CHART_TOPTIT] = RGB(255, 255, 255);

	
}

BOOL CCfxLabels::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	int i;
    
    m_pChartFX->OpenDataEx(COD_VALUES, 2, 10);
    for(i=0; i<10;i++) {
        m_pChartFX->ValueEx[0][i] = rand() % 50;
        m_pChartFX->ValueEx[1][i] = 60 + rand() % 30;
    }
    m_pChartFX->CloseData(COD_VALUES);
    
    m_pChartFX->Axis->Item[AXIS_Y]->Style = (CfxAxisStyle) (m_pChartFX->Axis->Item[AXIS_Y]->Style | AS_NOTIFY);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCfxLabels::OnCusylabels() 
{
	// TODO: Add your control notification handler code here


    if (IsDlgButtonChecked(IDC_CUSYLABELS))  
        m_pChartFX->LeftGap = m_pChartFX->LeftGap + 40;
	else
        m_pChartFX->LeftGap = m_pChartFX->LeftGap - 40;

	
}

void CCfxLabels::OnCuspointlabels() 
{
	// TODO: Add your control notification handler code here
	m_pChartFX->PointLabels = TRUE;
	m_pChartFX->Refresh();

}

BEGIN_EVENTSINK_MAP(CCfxLabels, CDialog)
    //{{AFX_EVENTSINK_MAP(CCfxLabels)
	ON_EVENT(CCfxLabels, IDC_CHART1, 29 /* GetAxisLabel */, OnGetAxisLabelChart1, VTS_I2 VTS_PI2)
	ON_EVENT(CCfxLabels, IDC_CHART1, 28 /* GetPointLabel */, OnGetPointLabelChart1, VTS_I4 VTS_I4 VTS_PI2)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CCfxLabels::OnGetAxisLabelChart1(short nAxis, short FAR* nRes) 
{
	// TODO: Add your control notification handler code here

    if (IsDlgButtonChecked(IDC_CUSYLABELS)) {
        m_pChartFX->HText = "Custom " + m_pChartFX->HText;
        *nRes = 1;
    }
	
}

void CCfxLabels::OnGetPointLabelChart1(long nSerie, long nPoint, short FAR* nRes) 
{
	// TODO: Add your control notification handler code here

    if (IsDlgButtonChecked(IDC_CUSPOINTLABELS)) {
		m_pChartFX->HText = "$"+ m_pChartFX->HText;
       *nRes = 1;
    }

	
}

⌨️ 快捷键说明

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