B4J Question Upload a JavaScript file in WebView B4J

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Put it in the same folder you put the html file and reference it from the html file.
B4X:
Dim jg As JSONGenerator
    jg.Initialize2(listY)
    Dim jg2 As JSONGenerator
    jg2.Initialize2(listX)
                
    WebView1.LoadHtml($"
            <canvas id="linechart" width=${WebView1.prefWidth-10dip} height=${WebView1.prefHeight-20dip}></canvas>
            <script src=${WebViewAssetFile("Chart.js")}></script>
            <script>
            var ctx = document.getElementById("linechart");
            ctx.style.backgroundColor = 'rgba(255,255,255,255)';
var linechart = new Chart(ctx,{
  type: 'line',
  data: {
    labels: ${jg2.ToString},
    datasets: [{
        data: ${jg.ToString},
        label: Luminarias,
        borderColor: "rgba(255, 116, 0, 1)",
        fill: True,
        backgroundColor: "rgba(255, 116, 0, 0.7)"

      }
    ]
  },
  options: {
    responsive: False,
    animation: False,
    title: {
      display: False,
      text: 'World population per region (in millions)'
    }
  }
});
</script>
        "$)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…