require: Need your help

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

require: Need your help

Post by Peter »

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: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: require: Need your help

Post by poshu »

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: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: require: Need your help

Post by falsam »

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 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

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

Re: require: Need your help

Post by falsam »

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 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

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

Re: require: Need your help

Post by Peter »

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: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: require: Need your help

Post by poshu »

So the "require a non-existent file" method works... Does any one know why though?
Post Reply