Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example causes typeError #42

Closed
toddbruner opened this issue Dec 16, 2015 · 2 comments
Closed

Example causes typeError #42

toddbruner opened this issue Dec 16, 2015 · 2 comments

Comments

@toddbruner
Copy link

Probably missing something simple but.

test.html

    <html>
      <head>
        <script type="text/javascript"
                src="/vast/libs/d3.js"></script>
        <script type="text/javascript"
                src="/vast/libs/d3.chart.js"></script>
        <script type="text/javascript"
                src="/vast/libs/d3.compose-all.js"></script>
        <link   type="text/css"
               href="/vast/css/d3.compose.css"
                rel="stylesheet"
               >
       <script>
        var data = [
            {x: 1, y: 100,},
            {x: 2, y: 200,},
            {x: 3, y: 150,}
        ];

        var chart = d3.select('#chart').chart('Compose', function(data){
            var charts = [
                d3c.lines('results', {data: data})
            ];
            return [
                d3c.layered(charts)
            ];
        });
        chart.draw(data);
    </script>
  </head>
  <body>
    <h1>Competed Count</h1>
    <div id="chart"></div>
  </body>
</html>

Generates the following Error:
Uncaught TypeError: Cannot read property 'tagName' of nullBase.extend.initialize @ d3.compose-all.js:2106Base @ d3.compose-all.js:1151Child @ d3.compose-all.js:1303d3.selection.chart @ d3.chart.js:721(anonymous function) @ vizstats.html:20

d3.js 3.5.5
d3.chart 0.2.1
everything else pulled from links on your website.

Thanks.

@john-clarke
Copy link
Contributor

I think this might be due to your script executing before the body is rendered. Also, you'll need to set the charset to utf-8 for d3.js. The following works for me (paths modified slightly):

<html>
  <head>
    <meta charset="utf-8">
    <link type="text/css" href="dist/d3.compose.css"rel="stylesheet" >
    <script type="text/javascript" src="dist/d3.js"></script>
    <script type="text/javascript" src="dist/d3.chart.js"></script>
    <script type="text/javascript" src="dist/d3.compose-all.js"></script>
    <script>
    function main() {
      var data = [
          {x: 1, y: 100,},
          {x: 2, y: 200,},
          {x: 3, y: 150,}
      ];

      var chart = d3.select('#chart').chart('Compose', function(data){
          var charts = [
              d3c.lines('results', {data: data})
          ];
          return [
              d3c.layered(charts)
          ];
      });
      chart.draw(data);
    }
    </script>
  </head>
  <body onload="main()">
    <h1>Competed Count</h1>
    <div id="chart"></div>
  </body>
</html>

Renders:
image

@timhall timhall closed this as completed Dec 16, 2015
@toddbruner
Copy link
Author

that indeed was the case, thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants