FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Algun ejemplo de twebview2 con google chart ?
Posts: 400
Joined: Tue Oct 16, 2007 05:51 PM
Algun ejemplo de twebview2 con google chart ?
Posted: Mon Dec 16, 2024 03:29 PM

Buen dia.

Abra algun ejemplo de twebview2 con google chart, pasando parametros por javascript desde prg ?

Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Mon Dec 16, 2024 06:19 PM

Albeiro,

Tienes el ejemplo FWH\samples\webchart.prg que usa TWebView()

Vamos a modificarlo para que use TWebView2()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 400
Joined: Tue Oct 16, 2007 05:51 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Tue Dec 17, 2024 02:15 AM
Antonio Linares wrote:Albeiro,

Tienes el ejemplo FWH\samples\webchart.prg que usa TWebView()

Vamos a modificarlo para que use TWebView2()
Muchas Gracias Antonio, revise el ejemplo, si no es mucho pedir, me gustaria si puedes agregar un Bar Chart o Pie Chart de google
usando oWebView:InjectJavascript.
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Wed Dec 18, 2024 06:36 AM
webchart2.prg
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oWnd, oWebView  

   DEFINE WINDOW oWnd TITLE "Google chart using Class TWebView2" SIZE 900, 500

   oWebView = TWebView2():New( oWnd )

   oWebView:SetHtml( Html() )

   ACTIVATE WINDOW oWnd CENTERED ;
      ON RESIZE oWebView:SetSize( nWidth, nHeight )

return nil

function Html()

   local cHtml

   TEXT INTO cHtml
        <!DOCTYPE html>
        <html>
        <head>
            <title>Google Bar Chart Example</title>
            <style>
                #loading {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    justify-content: center;
                    padding: 20px;
                    font-family: Arial, sans-serif;
                }

                .spinner {
                    width: 40px;
                    height: 40px;
                    border: 4px solid #f3f3f3;
                    border-top: 4px solid #3498db;
                    border-radius: 50%;
                    animation: spin 1s linear infinite;
                    margin-bottom: 10px;
                }

                @keyframes spin {
                    0% { transform: rotate(0deg); }
                    100% { transform: rotate(360deg); }
                }

                #chart_div {
                    min-height: 400px;
                }
            </style>
        </head>
        <body>
            <div id="loading">
                <div class="spinner"></div>
                <div>Cargando gráfico...</div>
            </div>
            <div id="chart_div"></div>

            <!-- Usar JSAPI directamente es más rápido -->
            <script src="https://www.google.com/jsapi"></script>
            <script>
                // Cargar la versión más ligera de Charts
                google.load('visualization', '1', {
                    packages: ['corechart'],
                    callback: drawChart
                });

                function drawChart() {
                    var data = google.visualization.arrayToDataTable([
                        ['Año', 'Ventas', 'Gastos'],
                        ['2020', 1000, 400],
                        ['2021', 1170, 460],
                        ['2022', 660, 1120],
                        ['2023', 1030, 540]
                    ]);

                    var options = {
                        title: 'Rendimiento de la Compañía',
                        width: 800,
                        height: 400,
                        bar: {groupWidth: "75%"},
                        legend: { position: "right" },
                        hAxis: { title: 'Valores en miles' },
                        vAxis: { title: 'Año' }
                    };

                    var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
                    chart.draw(data, options);
                    document.getElementById('loading').style.display = 'none';
                }
            </script>
        </body>
        </html>
   ENDTEXT

return cHtml
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Wed Dec 18, 2024 07:21 AM

> usando oWebView:InjectJavascript

Eso solo tiene sentido si vas a modificar una web que no has hecho tu.

Si lo que quieres es modificar desde tu aplicación los valores mostrados en el gráfico entonces se usa oWebView:Eval()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 400
Joined: Tue Oct 16, 2007 05:51 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Fri Dec 20, 2024 03:32 AM
Antonio, gracias funciona bien.

Modifique tu ejemplo para mostrar el envio de los valores a webview, lo pongo aqui para quien quiera
entenderlo mejor.
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oWnd, oWebView  

   DEFINE WINDOW oWnd TITLE "Google chart using Class TWebView2" SIZE 900, 500

   oWebView = TWebView2():New( oWnd )

   oWebView:SetHtml( Html() )
   oWebView:InjectJavascript( aDataJS() )
   oWebView:InjectJavascript( cJavaScript() )
   oWebView:Eval( "loadChart()" )

   ACTIVATE WINDOW oWnd CENTERED ;
      ON RESIZE oWebView:SetSize( nWidth, nHeight )

return nil

static function Html()

   local cHtml

   TEXT INTO cHtml
        <!DOCTYPE html>
        <html>
        <head>
            <title>Google Bar Chart Example</title>
            <style>
                #loading {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    justify-content: center;
                    padding: 20px;
                    font-family: Arial, sans-serif;
                }

                .spinner {
                    width: 40px;
                    height: 40px;
                    border: 4px solid #f3f3f3;
                    border-top: 4px solid #3498db;
                    border-radius: 50%;
                    animation: spin 1s linear infinite;
                    margin-bottom: 10px;
                }

                @keyframes spin {
                    0% { transform: rotate(0deg); }
                    100% { transform: rotate(360deg); }
                }

                #chart_div {
                    min-height: 400px;
                }
            </style>
        </head>
        <body>
            <div id="loading">
                <div class="spinner"></div>
                <div>Cargando gráfico...</div>
            </div>
            <div id="chart_div"></div>

            <!-- Usar JSAPI directamente es más rápido -->
            <script src="https://www.google.com/jsapi"></script>
            <script>
                
            </script>
        </body>
        </html>
   ENDTEXT

return cHtml

static function cJavaScript() 
  Local cHtml 
  
    TEXT INTO cHtml
        // Cargar la versión más ligera de Charts
     function loadChart() {
        google.load('visualization', '1', {
         packages: ['corechart'],
         callback: drawChart
        });
     }
     
     function drawChart() {
         var data = google.visualization.arrayToDataTable( aData );

         var options = {
             title: 'Rendimiento de la Compañía',
             width: 800,
             height: 400,
             bar: {groupWidth: "75%"},
             legend: { position: "right" },
             hAxis: { title: 'Valores en miles' },
             vAxis: { title: 'Año' }
         };

         var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
         chart.draw(data, options);
         document.getElementById('loading').style.display = 'none';
     }
    ENDTEXT 
    
return cHtml         

static function aDataJS()
    Local cHtml
    Local i
    Local nPos
    Local aData := { { "2020", 1000,  400 },;
                     { "2021", 1170,  460 },;
                     { "2022",  660, 1120 },;
                     { "2023", 1000,  540 },;
                     { "2024", 1030,  125 },;
                     { "2025",  235,  230 } } 
        
  cHtml  = "var aData = [ " + CRLF
  cHtml += "['Año', 'Ventas', 'Gastos']," + CRLF
  
  FOR i:=1 TO Len(aData)
        cHtml += "[" 
        cHtml += "'" + aData[i,1] + "'" + "," 
        cHtml += Str(aData[i,2]) + "," 
        cHtml += Str(aData[i,3]) 
        cHtml += "]," + CRLF
    NEXT i
    
    cHtml += "]" 
    
  ? cHtml
    
return cHtml
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Fri Dec 20, 2024 06:52 AM
Muy bien! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Fri Dec 20, 2024 04:10 PM
Excelente !
no hay imagen ? :D
Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Fri Dec 20, 2024 08:47 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Fri Dec 20, 2024 11:06 PM

Un gran ejemplo maestro,

gracias por compartir.

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Sun Dec 22, 2024 07:43 PM

Saludos

Alguna idea de porque NO me carga el grafico, uso xHarbour y FWH 24.09, se queda mostrando el texto de "Cargando grafico" y no pasa nada !!!

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Mon Dec 23, 2024 03:27 AM

Saludos Antonio

Solo para complementar, compile con Harbour y si funciono, el problema esta con xHarbour favor hay solucion ?

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Mon Dec 23, 2024 11:04 AM
Estimado Enrique,

La solución para que funcione con xHarbour es eliminar esta línea:

// Cargar la versión más ligera de Charts

Por lo visto el contenido de TEXT ... ENDTEXT se procesa de forma diferente en Harbour y xHarbour

xHarbour no procesa los retornos de carro y a partir de ese comentario, considera todo el código que sigue como parte del comentario.

Esta es una gran diferencia entre ambos compiladores (Harbour y xHarbour) que hay que investigar (estamos en ello) pues puede ocasionar
comportamientos muy diferentes como en este ejemplo.

Gracias por tu observación ya que ha puesto de manifiesto un detalle muy importante! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Mon Dec 23, 2024 11:46 AM

Saludos Antonio

Es correcto, sin esa linea, funciono bien, GRACIAS !!! ... ya tarea de los gurus como solucionar la diferencia.

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Algun ejemplo de twebview2 con google chart ?
Posted: Mon Dec 23, 2024 02:08 PM

La solución correcta es añadir esta regla despues del include:

include "FiveWin.ch"

xcommand TEXT INTO <v> => #pragma __cstream|<v>:=%s

regards, saludos

Antonio Linares
www.fivetechsoft.com