Chartist.js is throwing a TypeError: a is null

javascript chartist.js

1006 просмотра

1 ответ

6 Репутация автора

I know I am missing something dumb here. Any idea why I can't get my chart rendered?

TypeError: a is null error message in console.

<html>
<head>
<title>My first Chartist Tests</title>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">

 </head>
<body><script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>


<script type="text/javascript">

new Chartist.Line('.ct-chart', {
  labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
  series: [
      [12, 9, 7, 8, 5],
       [2, 1, 3.5, 7, 3],
      [1, 3, 4, 5, 6]
      ]
}, {
 fullWidth: true,
 chartPadding: {
    right: 40
 }
});

</script>
<div class="ct-chart ct-perfect-fourth"></div>
 </body>
</html>
Автор: Nicole Источник Размещён: 18.07.2016 08:23

Ответы (1)


2 плюса

8603 Репутация автора

live example

you should execute js codes after dom is fully loaded.try moving your script after the div (end of the body).

<html>
    <head>
        <title>My first Chartist Tests</title>
        <link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">

    </head>
    <body>
        <div class="ct-chart ct-perfect-fourth"></div>

        <script type="text/javascript" src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>

        <script type="text/javascript">

            new Chartist.Line('.ct-chart', {
                labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
                series: [
                    [12, 9, 7, 8, 5],
                    [2, 1, 3.5, 7, 3],
                    [1, 3, 4, 5, 6]
                ]
            }, {
                fullWidth: true,
                chartPadding: {
                    right: 40
                }
            });

        </script>
    </body>
</html>
Автор: Madhawa Priyashantha Размещён: 18.07.2016 08:49
Вопросы из категории :
32x32