Advertisement
nanda_danis

RxGgCharts.pas

Jul 25th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.55 KB | None | 0 0
  1. unit RxGgCharts;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, Dialogs, SysUtils,
  7.   RaControlsVCL;
  8.  
  9. type
  10.   TRxGgCharts = class(TRaExtendableControlGCD)
  11.   public
  12.     constructor Create(AOwner: TComponent); override;
  13.   protected
  14.     procedure RaDrawExtend(var AJavascript: String); override;
  15.   published
  16.     property Visible;
  17.   end;
  18.  
  19. procedure Register;
  20.  
  21. implementation
  22.  
  23. uses
  24.   RaCommon, main;
  25.  
  26. constructor TRxGgCharts.Create(AOwner: TComponent);
  27. begin
  28.   inherited;
  29.   SetBounds(Left, Top, 300, 300);
  30. end;
  31.  
  32. procedure TRxGgCharts.RaDrawExtend(var AJavascript: String);
  33. begin
  34.   AJavascript :=
  35.  
  36.     'var me=this;' +
  37.  
  38.     'me.onRender=function(){' +
  39.  
  40.       'me.getDOM().style.backgroundColor = "white";' +
  41.  
  42.       'me.r=me.require(["js","https://www.google.com/jsapi"],function(){' +
  43.  
  44.         'me.r=undefined;' +
  45.         'me.d=setTimeout(function(){' +
  46.           'me.d=undefined;' + #13#10 +
  47.  
  48.           // https://google-developers.appspot.com/chart/interactive/docs/gallery/piechart
  49.           // http://stackoverflow.com/questions/9519673/why-does-google-load-cause-my-page-to-go-blank
  50.           // https://groups.google.com/forum/?fromgroups#!topic/google-ajax-search-api/4HwmBkmAlOY
  51.  
  52.           'google.load("visualization", "1", {packages: ["corechart"], callback: function() {' + #13#10 +
  53.  
  54.             'var data = google.visualization.arrayToDataTable([' + #13#10 +
  55.               '["Task",     "Hours per Day"],' + #13#10 +
  56.               '["Work",     33],' + #13#10 +
  57.               '["Eat",      2],' + #13#10 +
  58.               '["Ngoding",  50],' + #13#10 +
  59.               '["Nongkrong",  10],' + #13#10 +
  60.               '["Commute",  2],' + #13#10 +
  61.               '["Watch TV", 2],' + #13#10 +
  62.               '["Sleep",    7]' + #13#10 +
  63.                 //ambil dari var script form main                
  64.                 //FMain.script +
  65.             ']);' + #13#10 +
  66.  
  67.             'var options = {' + #13#10 +
  68.               'title: "My Daily Activities"' + #13#10 +
  69.             '};' + #13#10 +
  70.  
  71.             'var chart = new google.visualization.PieChart(me.getDOM());' + #13#10 +
  72.             'chart.draw(data, options);' + #13#10 +
  73.  
  74.           '}});' + #13#10 +
  75.  
  76.         '},0);' +
  77.       '});' +
  78.     '};' +
  79.  
  80.     'me.onUnrender=function(){' +
  81.       'if(me.r){' +
  82.         'me.dontRequire(me.r);' +
  83.         'me.r=undefined;' +
  84.       '};' +
  85.       'if(me.d){' +
  86.         'clearTimeout(me.d);' +
  87.         'me.d=undefined;' +
  88.       '};' +
  89.     '};';
  90.          ShowMessage(AJavascript);
  91. end;
  92.  
  93. procedure Register;
  94. begin
  95.   RegisterComponents('Raudus X', [TRxGgCharts]);
  96. end;
  97.  
  98. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement