Here's a slightly adapted version of your code using a Gadget (instead of dominsert()):
Code: Select all
EnableExplicit
Enumeration
#mf
#GoogleChartGadget
EndEnumeration
Procedure.i WindowElement(Window, UseJquery.b=#True)
Protected winObject=WindowID(Window)
!return (v_winobject && v_winobject.element)? v_usejquery? $(v_winobject.element):v_winobject.element:null;
EndProcedure
Procedure.i LoadAsynchronously(FileName.s, *OnLoadFunction, FileType.s)
!return $.ajax({ url:v_filename, dataType:v_filetype, beforeSend:function(jqxhr, settings) { jqxhr.url = settings.url; } })
!.done(function(data, status, jqxhr) { p_onloadfunction(data,status,jqxhr.url); })
!.fail(function(jqxhr, status, errorThrown) { p_onloadfunction('',status,jqxhr.url,jqxhr.status,errorThrown); });
EndProcedure
Procedure LoadScript(FileName.s, *OnLoadFunction)
ProcedureReturn LoadAsynchronously(FileName, *OnLoadFunction, "script")
EndProcedure
Procedure GoogleChartGadget(Gadget, x, y, Width, Height)
If Gadget = #PB_Any
Gadget = ContainerGadget(Gadget, x, y, Width, Height)
Else
ContainerGadget(Gadget, x, y, Width, Height)
EndIf
CloseGadgetList()
!var selector = $(spider_GadgetID(v_gadget).div).find('.dijitContentPane');
;3 - Initialize Google Chart.
!// Load the Visualization API And the corechart package.
!google.charts.load('current', {'packages':['corechart'] });
!// Set a callback To run when the Google Visualization API is loaded.
!google.charts.setOnLoadCallback(drawChart);
!// Callback that creates And populates a Data table,
!// instantiates the pie chart, passes in the Data And
!// draws it.
!function drawChart() {
! // Create the Data table.
! var data = new google.visualization.DataTable()
! data.addColumn('string', 'Topping');
! data.addColumn('number', 'Slices');
! data.addRows([
! ['Mushrooms', 3],
! ['Onions', 1],
! ['Olives', 1],
! ['Zucchini', 1],
! ['Pepperoni', 2]
! ]);
! // Set chart options
! var options = {'title':'How Much Pizza I Ate Last Night',
! 'width' : 400,
! 'height': 300,
;! colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6'], ;un-comment for red color
! legend: { position: "right" }, //right or none
! is3D: true,
! };
! // Instantiate And draw our chart, passing in some options.
! var chart = new google.visualization.PieChart(selector[0]);
! chart.draw(data, options);
! chart.getImageURI()
!}
ProcedureReturn Gadget
EndProcedure
Procedure Loading(content.s, status.s, url.s, errorCode, error.s)
If status<>"success"
Debug "Loading: FAILED"
Debug "File: "+url
Debug "Error code: "+errorCode
Select errorCode
Case 401 : Debug "Error: Authentification Failed"
Case 404 : Debug "Error: File Not Found"
Case 500 : Debug "Error: Server Failed"
Case 504 : Debug "Error: Server Timeout"
Default : Debug "Error: "+error
EndSelect
Debug ""
ProcedureReturn
EndIf
OpenWindow(#mf, 0, 0, 500, 400, "Google Chart", #PB_Window_ScreenCentered)
SetWindowColor(#mf, RGB(255, 255, 255))
GoogleChartGadget(#GoogleChartGadget, 20, 20, 400, 300)
EndProcedure
LoadScript("https://www.gstatic.com/charts/loader.js", @Loading())
Greetings ... Peter