Just starting out? Need help? Post your questions and find answers here.
User avatar
Peter
 
Posts: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

require: Need your help

by Peter Wed Aug 22, 2018 8:54 am

Hello,

i try to make a new module for the JavaScript library ApexCharts using require. But no matter what I do, I always get an "Uncaught ReferenceError: ApexCharts is not defined".

here's my code:

Code: Select all
! $("body").append($("<div id='chart' style='width:500px;height:300px' />"));

! require(["https://cdn.jsdelivr.net/npm/apexcharts"], function(a, b, c) {

! var options = {
!    chart:    { type: 'line' },
!    series: [ { name: 'sales', data: [30,40,35,50,49,60,70,91,125] } ],
!    xaxis:    { categories: [1991,1992,1993,1994,1995,1996,1997,1998,1999] }
! }

! var chart = new ApexCharts(document.querySelector("#chart"), options);
! chart.render();   

! });


and here's the same snippet in a HTML-File that works out of the box:
Code: Select all
<!DOCTYPE html>
<html lang="en">

<head></head>

<body>
    <div id="chart" style="width:500px;height:300px"></div>
    <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
    <script>
 
      var options = {
        chart: { type: 'line' },
        series: [{ name: 'sales',  data: [30,40,35,50,49,60,70,91,125] }],
        xaxis: { categories: [1991,1992,1993,1994,1995,1996,1997,1998,1999] }
      }
       
      var chart = new ApexCharts(document.querySelector("#chart"), options);
      chart.render();   
       
    </script>
   
</body>

</html>


require drives me crazy. Image I'm desperate...
poshu
 
Posts: 73
Joined: Mon Feb 24, 2014 11:46 pm

Re: require: Need your help

by poshu Wed Aug 22, 2018 9:16 am

Have you tried with Falsam's alternative solution ? In a nutshell: try to require something which does not exist first... Dunno why or how, but it seems to fix the problem with babylon.js...
Last edited by poshu on Wed Aug 22, 2018 9:48 am, edited 1 time in total.
falsam
 
Posts: 269
Joined: Mon May 05, 2014 9:49 pm
Location: France

Re: require: Need your help

by falsam Wed Aug 22, 2018 9:33 am

poshu wrote:Have you tried with Falsam alternate solution ?
Unfortunately this is not the right solution. I have had other console errors that prevent the framework from working properly.

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
falsam
 
Posts: 269
Joined: Mon May 05, 2014 9:49 pm
Location: France

Re: require: Need your help

by falsam Wed Aug 22, 2018 10:11 am

Hello Peter.

This way we have a visual rendering, but with console errors that I don't understand !!
Code: Select all
! $("body").append($("<div id='chart' style='width:500px;height:300px' />"));

! require(['ApexCharts', "https://cdn.jsdelivr.net/npm/apexcharts"], function(ApexCharts) {

! var options = {
!    chart:    { type: 'line' },
!    series: [ { name: 'sales', data: [30,40,35,50,49,60,70,91,125] } ],
!    xaxis:    { categories: [1991,1992,1993,1994,1995,1996,1997,1998,1999] }
! }

! var chart = new ApexCharts(document.querySelector("#chart"), options);
! chart.render();   

! });
I'm trying to understand why this message!!!
Console wrote:spiderbasic/libraries/javascript/ApexCharts.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
User avatar
Peter
 
Posts: 553
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: require: Need your help

by Peter Wed Aug 22, 2018 10:55 am

Yeah! The boys are back in town! It works! :D
Image
falsam wrote:I'm trying to understand why this message!!!
Console wrote:spiderbasic/libraries/javascript/ApexCharts.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)

i think, that's because of the first Array-Element (which doesn't exists)

Image

Thanks a lot & Greetings ... Peter
poshu
 
Posts: 73
Joined: Mon Feb 24, 2014 11:46 pm

Re: require: Need your help

by poshu Wed Aug 22, 2018 1:19 pm

So the "require a non-existent file" method works... Does any one know why though?
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 2 guests