xlsgen > overview > Chart text boxes

 


Adding custom text boxes in charts

A custom text box is an piece of text that can be attached to any chart, i.e. it moves with it. It is possible to attach any number of custom text boxes to a chart, and also to format it. Last but not least, an hyperlink can be attached to a text box.

An interesting capability of custom text boxes is how they can accomodate rich formatting, the same applies to regular cells and is described here.

In addition to accepting normal and richly formatted text, a chart title supports the common options, accessed from the IXlsChartTextBox interface.

Here is a couple examples of custom text boxes, in C++ :

C/C++ code

xlsgen::IXlsWorkbookPtr wbk = engine->New( L"chart_textbox.xls");

xlsgen::IXlsWorksheetPtr wksht = wbk->AddWorksheet( L"Sheet1" );

wksht->Label[2][2] = L"Janvier";
wksht->Label[3][2] = L"Fevrier";
wksht->Label[4][2] = L"Mars";
wksht->Label[5][2] = L"Avril";
wksht->Label[6][2] = L"Mai";
wksht->Label[1][3] = L"2000";
wksht->Number[2][3] = 2;
wksht->Number[3][3] = 6;
wksht->Number[4][3] = 3;
wksht->Number[5][3] = 4;
wksht->Number[6][3] = 3;
wksht->Label[1][4] = L"2001";
wksht->Number[2][4] = 3;
wksht->Number[3][4] = 7;
wksht->Number[4][4] = 4;
wksht->Number[5][4] = 5;
wksht->Number[6][4] = 3;
wksht->Label[1][5] = L"2002";
wksht->Number[2][5] = 4;
wksht->Number[3][5] = 8;
wksht->Number[4][5] = 5;
wksht->Number[5][5] = 2;
wksht->Number[6][5] = 5;
wksht->Label[1][6] = L"2003";
wksht->Number[2][6] = 2;
wksht->Number[3][6] = 9;
wksht->Number[4][6] = 6;
wksht->Number[5][6] = 8;
wksht->Number[6][6] = 8;
wksht->Label[1][7] = L"2004";
wksht->Number[2][7] = 3;
wksht->Number[3][7] = 5;
wksht->Number[4][7] = 7;
wksht->Number[5][7] = 2;
wksht->Number[6][7] = 4;
wksht->Label[1][8] = L"2005";
wksht->Number[2][8] = 2;
wksht->Number[3][8] = 9;
wksht->Number[4][8] = 6;
wksht->Number[5][8] = 8;
wksht->Number[6][8] = 8;

xlsgen::IXlsWorksheetPtr wksht2 = wbk->AddWorksheet( L"Sheet2" );

xlsgen::IXlsChartPtr chart2 = wksht2->NewChart(xlsgen::charttype_lineXYZ,
					     8, //row1
					     1, //col1 
					     16, //row2
					     5 //col2
					     );

xlsgen::IXlsChartDataSourcePtr datasource2 = chart2->DataSource;
datasource2->SeriesInRows = TRUE;
datasource2->Range = L"Sheet1!R1C2:R4C8";
chart2->CustomProperties->ChartResizeWithWindow = TRUE;

// add a custom text box to the chart, attach an hyperlink to it

xlsgen::IXlsChartTextBoxPtr tb1 = chart2->AddTextBox();
tb1->Options->X = 10;
tb1->Options->Y = 20;
tb1->Options->Width = 80;
tb1->Options->Height = 20;

tb1->Options->Alignment->Horizontal = xlsgen::halign_left;

xlsgen::IXlsHyperlinkPtr hlink = wksht->NewHyperlink();
hlink->CellAnchor(L"Sheet1", 5, 1);
hlink->Caption = L"some caption";
tb1->Hyperlink = hlink;

xlsgen::IXlsStylePtr style = wksht->NewStyle();
style->Borders->Bottom->Color = xlsgen::colorRed;
style->Borders->Bottom->Style = xlsgen::border_dashed;
style->Pattern->Pattern = xlsgen::pattern_12gray;
style->Pattern->BackgroundColor = xlsgen::colorGreen;
style->Font->Color = 0xFF0000;
style->Apply();

xlsgen::IXlsStylePtr style2 = style->Duplicate();
style2->Font->Color = 0x0000FF;
style2->Font->Bold = TRUE;
style2->Font->Size = 7;
style2->Apply();

xlsgen::IXlsRichLabelPtr rll = wksht->NewRichLabel();
rll->Label(L"label1\n",style);
rll->Label(L"label2",style2);
tb1->RichLabel = rll;

// add another custom text box

xlsgen::IXlsChartTextBoxPtr tb2 = chart2->AddTextBox();
tb2->Options->X = 10;
tb2->Options->Y = 60;
tb2->Options->Width = 80;
tb2->Options->Height = 15;
tb2->Options->Font->BackgroundType = xlsgen::chartfontbkground_opaque;
tb2->Label = L"some label";

wbk->Close();

 

xlsgen documentation. © ARsT Design all rights reserved.