BCGControlBar Pro for MFC
CBCGPChartLegendCell

Detailed Description

The CBCGPChartLegendCell class implements the functionality of individual legend cell. It encapsulates a BCGPChartCellParams object that defines cell appearance.

A cell can be one of the following enumerated types:

  • LCT_KEY - displays series key
  • LCT_LABEL - displays series or data point label
  • LCT_CHART_NAME - displays related chart name
  • LCT_CUSTOM - custom cell (displays custom text). You can override OnCalcCustomCellSize and OnDrawCustomCell to display custom content.

If you wish to display custom content in a "standard" cell, you have to override CalcSize and OnDraw methods.

All "standard" cells are created automatically by parent legend. CBCGPChartLegendCell::UpdateCellParams is called to obtain cell parameters from related charts and series. You can override CBCGPChartLegendVisualObject::OnLegendContentCreated or process BCGM_ON_CHART_LEGEND_CONTENT_CREATED to customize cell appearance, or add new legend entries and cells.

The following example illustrates how to add an entry (legend row) with two custom cells at the top of the legend:

Copy
LRESULT CMyView::OnLegendContentCreated(WPARAM, LPARAM lp)
{
CBCGPChartLegendEntry* pEntryHead = new CBCGPChartLegendEntry(pLegend);
CBCGPChartLegendCell* pCell1 = new CBCGPChartLegendCell("Head Item");
CBCGPChartLegendCell* pCell2 = new CBCGPChartLegendCell("Head Value");
pEntryHead->AddLegendCell(pCell1);
pEntryHead->AddLegendCell(pCell2);
pLegend->InsertLegendEntry(pEntryHead, 0);
return 0;
}

The following example illustrates how to change fill color, text color and content padding for all cells in column 0:

Copy
LRESULT CLegendTest1View::OnLegendContentCreated(WPARAM, LPARAM lp)
{
for (int i = 0; i < pLegend->GetLegendEntryCount(); i++)
{
CBCGPChartLegendCell* pCell = pLegend->GetLegendCell(i, 0);
params.m_brTextColor = CBCGPBrush(CBCGPColor::DarkRed);
params.m_brContentFill = CBCGPBrush(CBCGPColor::Yellow);
pCell->SetCellParams(params);
}
return 0;
}

Note, that legend cells are destroyed when the legend content is invalidated, therefore you should not store pointers to cells. Any customization is also lost, therefore it's highly recommended to apply customization in CBCGPChartLegendVisualObject::OnLegendContentCreated handler (or override).

If you change number of series or data points after a chart has been connected to a legend (using CBCGPChartLegendVisualObject::AddRelatedChart) and want to reflect these changes in legend, call CBCGPChartLegendVisualObject::InvalidateLegendContent.

If you change directly (through access to BCGPChartCellParams members) any cell or legend properties that affect size (for example, text format) call CBCGPChartLegendVisualObject::InvalidateLegendSize.

Inherits CObject.

Public Member Functions

 CBCGPChartLegendCellThe constructor
 
 CBCGPChartLegendCellThe constructor
 
 CalcSizeCalled to calculate cell size
 
 ContainsSeriesTells whether a cell displays a legend of specified series and data point
 
 GetCellParamsReturns a reference to current cell parameters
 
 GetCellTextReturns cell text
 
 GetCellTypeReturns cell type
 
 GetCustomDataReturns a pointer to a custom CObject - derived class associated with legend
 
 GetHitRectReturns hit rectangle of cell
 
 GetRelatedChrtReturns a pointer to related chart
 
 GetRelatedDataPointIndexReturns related data point index
 
 GetRelatedSeriesReturns a pointer to related series
 
 GetSizeGets the cell size.
 
 GetTextAlignmentGets chart legend cell text alignment.
 
 OnDrawCalled to render cell content
 
 OnScaleRatioChangedCalled when scale ratio has changed
 
 RedrawRedraws the legend cell.
 
 SetCellParamsSets cell parameters.
 
 SetCellTextSets new cell label
 
 SetCustomDataCall this method to associate legend with a custom data.
 
 SetTextAlignmentSets chart legend cell text alignment.
 
 SetTextFormatSets text format.
 
 UpdateCellParamsGathers cell parameters from related charts and series
 

Protected Member Functions

 OnCalcCustomCellSizeCalled to calculate size of custom cell (cell with LCT_CUSTOM type)
 
 OnDrawCustomCellCalled to draw custom cells (cells with LCT_CUSTOM style)
 
 OnFillCellBackgroundCalled to fill cell background