Objective Chart : PART I User’s Guide : Chapter 7 Customizing a Chart : Component Panel Appearance
Component Panel Appearance
The appearance of a component’s background, border, and shadow are controlled by settings in the component’s style data member.
SRGraphComponent::GetStyle() returns a pointer to the component’s style object.
These functions control the general appearance of the component:
SRGraphStyle::SetComponentFillStyle()
SetComponentBorderStyle()
SetComponentShadowStyle()
For example, the code below creates a title component with a gradient fill, a thick border, and a medium shadow.
 
SRGraphTitle* pB=new SRGraphTitle;
SRGraphStyle* pS=pB->GetStyle();
pS->SetComponentFillStyle(CX_VERTICAL_FILL);
pS->SetColor(CXCLR_TEAL, CXCLR_MAGENTA);
pS->SetComponentShadowStyle(CX_MEDIUM_SHADOW);
pS->SetComponentBorderStyle(CX_THICK_RAISED_BORDER);
The component style settings are discussed in the following sections.
Component Border Styles
Use SetComponentBorderStyle() to select the border styles presented in Table 5.
Table 4 – Border styles 
Border Style
Description
CX_NO_BORDER
 
CX_THIN_RAISED_BORDER
The panel appears to be raised above the surface.
CX_THIN_SUNKEN_BORDER
The panel is let into the surface.
CX_THIN_3D_BORDER
The panel has beveled edges.
CX_THICK_RAISED_BORDER
 
CX_THICK_SUNKEN_BORDER
 
CX_THICK_3D_BORDER
This style is similar to those above but is more pronounced.
CX_LINE_BORDER
The border is a simple line whose color is determined by the frame color of the local style member.
CX_USER_BORDER
User defined — override DrawCustomBorder()
Component Shadow Styles
The following shadow styles can be selected with SetComponentShadowStyle().
Table 5 – Shadow styles 
CX_NO_SHADOW
CX_THIN_SHADOW
CX_MEDIUM_SHADOW
CX_THICK_SHADOW
CX_USER_SHADOW
User defined — override DrawCustomShadow()
Component Fill Styles
A component may be filled with a solid color, a color gradient, or a tiled or stretched image from the application’s resources or a bitmap, DIB, or JPEG file. Components may also be left with no fill, in which case any data or text that the component displays on its foreground is superimposed on anything already on the page or window.
The following fill styles can be selected with SetComponentFillStyle().
Table 6 – Fill styles 
Fill Style
Description
CX_NO_FILL
No drawing takes place. The panel is transparent.
CX_SOLID_FILL
The color in the m_RGBColorA member of the local style is used. See SRGraphStyle::SetColor(color).
CX_VERTICAL_FILL
A vertical color gradient from the m_RGBColorA (top) to the m_RGBColorB (bottom) member of the local style is created. See SRGraphStyle::SetColor(a,b).
CX_HORIZONTAL_FILL
Similar to the above setting but the gradient goes left to right.
CX_ANGLE_FILL
A gradient is drawn at an angle determined by the m_dAngle member of the local style. See SRGraphStyle::SetAngle().
CX_RESOURCE_FILL
Uses a bitmap resource from the application’s resources to tile or stretch fill the panel. Tiling or stretching is controlled by SRGraphStyle::SetStretchMode(). The name of the resource is set by SRGraphStyle::SetResourceName().
CX_IMAGE_FILL
Uses an image read from a bitmap, DIB, or JPEG file on disk. SetResourceName() and SetStretchMode() select the image file and how it is displayed.
CX_USER_FILL
User defined — override DrawCustomRgnFill()
As noted, these fill styles may require the specification of other settings.
To select a solid color background:
 
SRGraphTitle* pT=new SRGraphTitle;
SRGraphStyle* pS=pT->GetStyle();
pS->SetComponentFillStyle(CX_SOLID_FILL);
pS->SetColor(CXCLR_BLUE); // style
or
 
pT->SetColor(CXCLR_BLUE, CXCLR_BLUE); // component
To select a vertical or horizontal color gradient:
 
SRGraphTitle* pT=new SRGraphTitle;
SRGraphStyle* pS=pT->GetStyle();
pS->SetComponentFillStyle(CX_VERTICAL_FILL);
// or CX_HORIZONTAL_FILL
// blue top, red bottom
pS->SetColor(CXCLR_BLUE, CXCLR_RED);
To select an angled color gradient:
 
SRGraphTitle* pT=new SRGraphTitle;
SRGraphStyle* pS=pT->GetStyle();
pS->SetComponentFillStyle(CX_ANGLE_FILL);
// blue top-left, red bottom-right
pS->SetColor(CXCLR_BLUE, CXCLR_RED);
pS->SetAngle(45.); // degrees
To display a resource bitmap in the background:
Add the name of the bitmap file to the application’s resources. The bitmap must be identified by name not by symbol. The identifier should appear in the ResourceView enclosed by double quotes (e.g. “BG1”).
Set the component fill style to CX_RESOURCE_FILL and call SetResourceName() with the ID name of the bitmap file.
 
SRGraphTitle* pB=new SRGraphTitle;
SRGraphStyle* pS=pB->GetStyle();
pS->SetComponentFillStyle(CX_RESOURCE_FILL);
pS->SetResourceName(“BG1”);
pS->SetStretchMode(TRUE); //True=stretch, False=tile
To display a bitmap, DIB, or JPEG file in the background:
Set the component fill style to CX_IMAGE_FILL and call SetResourceName() with the path of the image file.
 
SRGraphDisplay* pD=new SRGraphDisplay;
pD->GetStyle()->SetComponentFillStyle(CX_IMAGE_FILL);
pD->GetStyle()->SetResourceName(_T("bg2.bmp"));
pD->GetStyle()->SetStretchMode(FALSE); // tile
or
 
SRGraphBackground* pB = new SRGraphBackground;
pB->GetStyle()->SetComponentFillStyle(CX_IMAGE_FILL);
pB->GetStyle()->SetResourceName(_T("stinglogo.jpg"));
pB->GetStyle()->SetStretchMode(TRUE); // stretch
To keep a component from erasing its background:
Set the component fill style to NO_FILL for transparent drawing.
To dynamically hide/show a component:
The only way to hide a component is to remove it from the component list. As long as the component is not a Legend, which is position dependent, this is not difficult to do. The component list is a CObList and it can be manipulated using standard MFC techniques.
Save the pointer to the component and a flag with the current hide/show state along with the m_Graph object.
The code segment below demonstrates hiding and showing an SRGraphTitle component from member functions of a CGraphDoc-derived class. The pointer and flag member variables are m_pT and m_bTShow, respectively.
 
void DocClass::HideTitle()
{
int i=0;
SRGraphTitle* pT;
do
{
pT = (SRGraphTitle *)m_Graph.GetComponent(i++, IDS_SRG_TITLETYPE);
}while( (pT!=NULL) && (pT!=m_pT));
if(pT != NULL)
{
CObList* pList= m_Graph.GetComponentList();
pList->RemoveAt(pList->Find(pT));
m_bTPShow=FALSE;
}
UpdateAllViews(NULL);
}
 
void DocClass::ShowTitle()
{
m_Graph.AddComponent(m_pT);
m_bTShow=TRUE;
UpdateAllViews(NULL);
}
Remember to add a line in your cleanup code (destructor) because m_Graph will not delete the component if it is not in its component list:
 
if(!m_bTShow) delete m_pT;