Error "Can not read property 'x' of undefined" Raphael.js

1

I have the following error when using the browser:

  

Uncaught TypeError: Can not read property 'x' of undefined

And it does not show me anything. Using the jsfiddle function perfectly and I have no error using the same code. I think it will be library problem.

<script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>

Exampleon jsfiddle

    
asked by anonymous 22.04.2015 / 13:36

1 answer

1

You have two problems;

  • You added Raphal.js twice

    <script type="text/javascript" src="raphael.js"></script>
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>

    Orusetheproductionversionorcdn.

  • ItestedyesterdayanddidnotseethiserrorUncaughtTypeError:Cannotreadproperty'x'ofundefineduntilcallingtheconstructortogenerateanSVG,whathappensisthatthepagehadnotfinishedloadingbeforerunningRaphal.js,youcandoitintwoways:

    • Usingwindow.onload:

      window.onload=function(){varpaper=Raphael("canvas", 640, 480);
              paper.clear();
              paper.circle(320, 240, 60);
      };
      
    • Using jQuery.ready :

      $(function() {
          var paper = Raphael("canvas", 640, 480);
              paper.clear();
              paper.circle(320, 240, 60);
      });
      
  • Sample html code:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Exemplo simples</title>
        <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script><scripttype="text/javascript">
        window.onload = function() {
            var paper = Raphael("canvas", 640, 480);
                paper.clear();
                paper.circle(320, 240, 60);
        };
        </script>
    </head>
    <body>
        <div id="canvas"></div>
    </body>
    </html>
    
        
    22.04.2015 / 14:22