Gene Bo
Gene Bo

Reputation: 12073

morris.js Graph container element not found

Why am I getting an exception

Uncaught Error: Graph container element not found

when using morris.js?

Upvotes: 34

Views: 109164

Answers (6)

Adnan
Adnan

Reputation: 1293

I have copied some scripts containing morris implementation and had this problem. Apparently, the scripts are initializing 3 morris charts when in my HTML I only had implemented 1 element, so it was failing to initialize the bars for the unexisting elements

Upvotes: 0

Anatole Nkwadjo
Anatole Nkwadjo

Reputation: 111

if don' t use the chart on this page, you can do this:

  1. Go to the line where the exception is throwed in morris.js
  2. change it like this: before:

      if (this.el === null || this.el.length === 0) {
       return;
        // throw new Error("Graph placeholder not found.");
      } 
    

Upvotes: 9

Milind Babar
Milind Babar

Reputation: 11

Try This

<head>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://cdn.oesmith.co.uk/morris-0.4.1.min.js"></script>
</head>
<body>
    <div id="donut-example"></div>

                    <script type="text/javascript">
                        Morris.Donut({
                            element: 'donut-example',
                            data: [
                              { label: "Download Sales", value: 12 },
                              { label: "In-Store Sales", value: 30 },
                              { label: "Mail-Order Sales", value: 20 }
                            ]
                        });
                    </script>

    </div>
</body>

Upvotes: 1

rdotjs
rdotjs

Reputation: 61

I had this issue when I was using the node.js framework. Taking out the script tags containing the morris charts and the jquery from the bottom of the html file worked for me. I am using Require.js to load the dependencies for my project instead. I hope this helped.

Upvotes: 2

Panchal Deep
Panchal Deep

Reputation: 257

JavaScript's code gets executed before the DOM contains #annual element. Put the javascript after the div or use jQuery.ready()

Upvotes: 0

Gene Bo
Gene Bo

Reputation: 12073

Solution: Put the javascript after the morris.js div

From this post from tiraeth: https://github.com/morrisjs/morris.js/issues/137

Upvotes: 36

Related Questions