Charts [examples]

Agregate data from multiple records. Data for a Chart section consists of a comma-separated string. SQLEVAL() returns string from a singleton SQL select. It also creates an array called _sqlvalues when SQL select returns multiple rows. ASTRING() returns comma-separated string from an array.

//strselect.prg - created in the Library for use in any App
parameter p_sqlselect
sqleval(p_sqlselect)
return astring(_sqlvalues)

https://www.lianja.com/doc/index.php/Data_Visualization_with_Charts


Generate a background report PDF when a bar is clicked.

////////////////////////////////////////////////////////////////
// Event delegate for 'click' event
proc page1_section1_click(arg)
 
    // Position on the correct Employeeid using SEEK()
    if seek(val(arg),employees)
        // Refresh the Employees Section
        Lianja.getelementbyid("Page1.section2").refresh()
        // Generate and display a PDF report on the employee's orders
        // using a hidden WebView Section and the Library report.rsp
        myreport = createObject("webview") 
        myreport.url = "lib:/report.rsp?database=southwind&table=orders";
            +"&fields=*&filter=employeeid={employees.employeeid}";
            +"&heading=Orders for Employee {employees.employeeid}"
        myreport.refresh()
        cTempfile = sys(3) + ".pdf"
        myreport.print('', 'Portrait', 'PDF', cTempfile)
        showdocument("file:///"+cTempfile)
    endif
endproc

https://www.lianja.com/doc/index.php/Data_Visualization_with_Charts


Data groups are separated with the | character.

Attribute Value
Data 1,2,3|4,5,6|7,8,9
Attribute Value
Data {sqleval(“select sum(unitsinstock), sum(unitsonorder) from products where categoryid = 1”)} | {sqleval(“select sum(unitsinstock), sum(unitsonorder) from products where categoryid = 2”)} | {sqleval(“select sum(unitsinstock), sum(unitsonorder) from products where categoryid = 3”)}
Attribute Value
Data {sqleval(“select sum(unitsinstock), sum(unitsonorder) from southwind.products where categoryid = 1”)} | {sqleval(“select sum(unitsinstock), sum(unitsonorder) from southwind.products where categoryid = 2”)} | {sqleval(“select sum(unitsinstock), sum(unitsonorder) from southwind.products where categoryid = 3”)}

When Value attribute is of this length, it is easier to write a script in the Library and is called.

Attribute Value
Data {page1_vbar1(“data”)}
Labels {page1_vbar1(“labels”)}
Tooltips {page1_vbar1(“tooltips”)}
// page1_vbar1.prg
// Script for Section vbar1 on Page page1
parameters p_prop
private m_return = ""
if pcount() != 1
	return m_return
endif
do case
case lower(p_prop) = "labels"
	select distinct ltrim(etos(employeeid)) from southwind.employees;
	order by employeeid into array m_labelarray
	m_return = astring(m_labelarray)
case lower(p_prop) = "tooltips"
	select distinct ltrim(etos(employeeid)) from southwind.employees;
	order by employeeid into array m_toolarray
	for i = 1 to alen(m_toolarray)
		m_return = m_return + m_toolarray(i) + ",";
		+ m_toolarray(i) + ",";
		+ m_toolarray(i) + ","
	next
	m_return = left(m_return,len(m_return)-1)
case lower(p_prop) = "data"
	if not isserver()
		// save data context if running on desktop
		save datasession
	else
		open database southwind
	endif
	use orders order employeeid in 0
	use employees order employeeid in 0
	scan
		select orders
		m_count2009 = cntvalues(year(orderdate)=2009, employees.employeeid)
		m_count2010 = cntvalues(year(orderdate)=2010, employees.employeeid)
		m_count2011 = cntvalues(year(orderdate)=2011, employees.employeeid)
		m_return = m_return + ltrim(str(m_count2009)) + "," ;
		+ ltrim(str(m_count2010)) + "," + ltrim(str(m_count2011))+"|"
		select employees
	endscan
	if not isserver()
		// restore data context
		restore datasession
	endif
	return left(m_return,len(m_return)-1)
endcase
return m_return

https://www.lianja.com/doc/index.php/Data_Visualization_with_Charts