OT: API Google crear gráficas

HMG en Español

Moderator: Rathinagiri

User avatar
tonton2
Posts: 291
Joined: Sat Jun 29, 2013 1:26 pm
Location: Algerie
Has thanked: 7 times
Been thanked: 11 times
Contact:

Re: OT: API Google crear gráficas

Post by tonton2 » Thu Nov 29, 2018 5:18 pm

mais ,c'est avec une base de données variable que je n'arrive pas a réaliser(le nombre de référence est variable).

traduction google:
but it is with a variable database that I can not seem to realize (the reference number is variable).
L'Algerie vous salut
Y.TABET

mlnr
Posts: 88
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF
Location: Hungary
Has thanked: 27 times
Been thanked: 9 times

Post by mlnr » Mon May 27, 2019 7:23 am

Hi,

Edward's sample is working like a charm, but when i modified a combo chart, then does not appear the generated html.
GoogleChart.html file is ready and appears in browser.
What could be the problem?

Code: Select all

/*
https://developers.google.com/chart/
*/

#include "hmg.ch"

Function Main()

DEFINE WINDOW Win_1 AT 192 , 422 WIDTH 600 HEIGHT 500 TITLE "Google Chart Html Sample" MAIN

	@ 60,390 TEXTBOX t_Width ;
		WIDTH 50 ;
		VALUE 480 ;
		NUMERIC INPUTMASK "999" 

	@ 100,390 TEXTBOX t_Height ;
		WIDTH 50 ;
		VALUE 250 ;
		NUMERIC INPUTMASK "999" 

	@ 60,340 LABEL Label_2 ;
		WIDTH 50 HEIGHT 20 ;
		VALUE 'Width'
    
	@ 100,340 LABEL Label_3 ;
		WIDTH 50 HEIGHT 20 ;
		VALUE 'Height'

	@ 100, 460 BUTTON Button_1 ;
		CAPTION "Generate" ;
		ACTION GoogleChartApi_() ;
		WIDTH  70 HEIGHT 28 

    DEFINE ACTIVEX Activex_1
        ROW    150
        COL    20
        WIDTH  540
        HEIGHT 200
        PROGID "shell.explorer.2"
    END ACTIVEX

END WINDOW

HMG_ChangeWindowStyle(GetControlHandle("Activex_1","Win_1"), WS_EX_CLIENTEDGE, NIL, .T.)
oActiveX:= GetProperty('Win_1','Activex_1','Object')
oActiveX:Silent := 1

END WINDOW

CENTER WINDOW Win_1

ACTIVATE WINDOW Win_1

Return Nil

****************************************************************************************
Function GoogleChartApi_()

Local cApiUrl := "https://chart.googleapis.com/chart"
Local cPOSTdata := ""
LOCAL oGoogle, cGoogleResp
Local cChartType := "ColumnChart"
Local cChartWidth := Alltrim(STR( Win_1.t_Width.Value ) )
Local cChartHeight := Alltrim(STR( Win_1.t_Height.Value ) )
Local i, cChartData := "", cChartLabel := ""
Local cHeaders := "User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)"
Local cHtmlFile := "GoogleChart.html"
Local cLocalUrl := "file:///" + GetCurrentFolder() + "/" + cHtmlFile
Local cHtmlString := "" 		//"<!-- saved from url=(0017)" + "http://localhost/" /* cLocalUrl */ + " -->" + CRLF

cHtmlString += "<html>" + CRLF 
cHtmlString += "<head>" + CRLF 
cHtmlString += '<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>' + CRLF 
cHtmlString += '<script type="text/javascript">' + CRLF 
cHtmlString += "google.charts.load('current', {'packages':['corechart']});" + CRLF 
cHtmlString += "google.charts.setOnLoadCallback(drawVisualization);" + CRLF 

cHtmlString += "function drawVisualization() {" + CRLF 
	cHtmlString += "var data = google.visualization.arrayToDataTable([" + CRLF 
		cHtmlString += "['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua New Guinea', 'Rwanda', 'Average']," + CRLF 
    cHtmlString += "['2004/05',  165,      938,         522,             998,           450,      614.6]," + CRLF 
    cHtmlString += "['2005/06',  135,      1120,        599,             1268,          288,      682]," + CRLF 
    cHtmlString += "['2006/07',  157,      1167,        587,             807,           397,      623]," + CRLF 
    cHtmlString += "['2007/08',  139,      1110,        615,             968,           215,      609.4]," + CRLF 
    cHtmlString += "['2008/09',  136,      691,         629,             1026,          366,      569.6]" + CRLF 
		cHtmlString += "]);" + CRLF 

		cHtmlString += "var options = {" + CRLF 
          cHtmlString += "title : 'Monthly Coffee Production by Country'," + CRLF 
          cHtmlString += "vAxis: {title: 'Cups'}," + CRLF 
          cHtmlString += "hAxis: {title: 'Month'}," + CRLF 
          cHtmlString += "seriesType: 'bars'," + CRLF 
          cHtmlString += "series: {5: {type: 'line'}}" + CRLF 
					cHtmlString += "};" + CRLF 

        cHtmlString += "var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));" + CRLF 
        cHtmlString += "chart.draw(data, options);" + CRLF 
				cHtmlString += "}" + CRLF 
				cHtmlString += "</script>" + CRLF 
				cHtmlString += "</head>" + CRLF 
				cHtmlString += "<body>" + CRLF 
				cHtmlString += '<div id="chart_div" style="width: '+cChartWidth+'px; height: '+cChartHeight+'px;"></div>' + CRLF 
				cHtmlString += "</body>" + CRLF 
				cHtmlString += "</html>" + CRLF 

STRFILE( cHtmlString , cHtmlFile)

Win_1.Activex_1.Width := Win_1.t_Width.Value + 70
Win_1.Activex_1.Height := Win_1.t_Height.Value + 50
oActiveX:= GetProperty('Win_1','Activex_1','Object')

oActiveX:Silent := 1
oActiveX:Navigate( cLocalUrl , , , , cHeaders)

RETURN 
Attachments
GoogleChart.png
GoogleChart.png (19.49 KiB) Viewed 279 times
Best regards,
Gabor

User avatar
mustafa
Posts: 829
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 117 times
Contact:

Post by mustafa » Mon May 27, 2019 10:38 am

Hi friend minr
replace these lines

Code: Select all

* cHtmlString += "<html>" + CRLF 
* cHtmlString += "<head>" + CRLF 
for this line of code

Code: Select all

cHtmlString += '<html>  <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" />  <meta charset="utf-8">' + CRLF + '<!--Load the AJAX API-->'  + CRLF
This is working well

View

viewtopic.php?f=24&t=5718&start=10
"API de Google crea gráficas3.zip"

Regards
Mustafa

mlnr
Posts: 88
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF
Location: Hungary
Has thanked: 27 times
Been thanked: 9 times

Post by mlnr » Mon May 27, 2019 10:46 am

Hello Mustafa,

Great!
It really works, thank you so much.
Best regards,
Gabor

Post Reply