3.9.6.1.3 Report with Embedded Graphs


Version Info

Minimum Origin Version Required: Origin 8 SR0

Examples

The following example shows how to embed graphs into report tables.

void Datasheet_SetReportTree_Ex3(string strGraphName = "Graph1")
{
	GraphPage gp(strGraphName);
	if(!gp)
	{
		printf("No graph named %s in project\n", strGraphName);
		return;
	}
	
	int nID = 100; // Each node must have node ID and node ID must be unique	
	int nTableFormat = GETNBRANCH_OPEN | GETNBRANCH_HIDE_COL_HEADINGS| GETNBRANCH_HIDE_ROW_HEADINGS | GETNBRANCH_FIT_COL_WIDTH | GETNBRANCH_FIT_ROW_HEIGHT;
	
	// 1. Create report tree
	Tree tr;
	tr.Report.ID = nID++; 
	tr.Report.SetAttribute(STR_LABEL_ATTRIB, "Report with Embedded Graph"); //Table title
	// TREE_Table attribute is critical in getting the report to work so must be present in every table level. 
	// Can set this attribute as 0 without any format, but many bits GETNBRANCH_* defined in oc_const.h to set table display format.
	tr.Report.SetAttribute(TREE_Table, nTableFormat); 	

	// 2. Put graph page inside report table
	tr.Report.Table1.ID = nID++;	
	tr.Report.Table1.strVal = gp.GetUID(true);
	tr.Report.Table1.SetAttribute(TREE_Control, ONODETYPE_EMBED_GRAPH);		

	// 3. Prepare worksheet window to report
	WorksheetPage wksPage;
	wksPage.Create("origin", CREATE_EMPTY);	
	wksPage.SetShow();	
	
	DWORD 	dwOptions = WP_SHEET_HIERARCHY | CREATE_NO_DEFAULT_TEMPLATE;		
	string	strSheetName = "Report Sheet";
	int nn = wksPage.AddLayer(strSheetName, dwOptions);
	if( nn < 0 )	
		return;		
	
	// 4. Do report
	Worksheet wksOut = wksPage.Layers(nn);
	if( wksOut.SetReportTree(tr.Report) < 0 ) // Returns last row number on successful exit and -1 on failure.
	{
		printf("Fail to set report tree.\n");
		return;
	}		
	wksPage.Rename("ReportSample");
	wksOut.AutoSize();		
}