2016-09-22 86 views
1

我用Chart.js制作了多个图形。但极地图形和雷达不起作用。我得到以下错误:“遗漏的类型错误:无法读取属性空的‘长度’”错误:“未捕获的类型错误:无法读取null属性'长度'Chart.js

我用charjs 2.3.0

我不明白的地方的错误能来。

<div class="col-lg-6 col-md-6"> 
    <canvas class="box box-warning" id="myChart4" width="400" height="400"></canvas> 
</div> 

<div class="col-lg-6 col-md-6"> 
    <canvas class="box box-warning" id="myChart5" width="400" height="400"></canvas> 
</div> 

////////////////////////////////////////////// 
// Chart Polar 
////////////////////////////////////////////// 

var ctx = document.getElementById("myChart4"); 

new Chart(ctx, { 
    type: 'polarArea', 
    data: { 
     labels: [ 
      "Red", 
      "Blue", 
      "Yellow" 
     ], 
     datasets: [{ 
      data: [300, 50, 100], 
      backgroundColor: [ 
       "#FF6384", 
       "#36A2EB", 
       "#FFCE56" 
      ], 
      hoverBackgroundColor: [ 
       "#FF6384", 
       "#36A2EB", 
       "#FFCE56" 
      ] 
     }] 
    }, 
    options: { 
     cutoutPercentage: 50, 
     animation: { 
      animateScale: false 
     } 
    } 
}); 

////////////////////////////////////////////// 
// Radar 
////////////////////////////////////////////// 

var ctx = document.getElementById("myChart5"); 


var scatterChart = new Chart(ctx, { 
    type: 'radar', 
    data: data = { 

     labels: ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche", ], 
     datasets: [{ 
      label: 'the first dataset', 
      backgroundColor: 'rgba(255, 99, 132, 0.2)', 
      borderColor: 'rgba(255,99,132,1)', 
      data: [10, 34, 50, 34, 56, 65, 43] 
     }, { 
      label: 'the second dataset', 

      backgroundColor: 'rgba(54, 162, 235, 0.2)', 
      borderColor: 'rgba(54, 162, 235, 1)', 

      data: [54, 72, 100, 36, 76, 23, 21] 
     }] 
    }, 
    options: { 
     scales: { 
      xAxes: [{ 
       type: 'linear', 
       position: 'bottom' 
      }] 
     } 
    } 
}); 
+0

与你的代码试图chart.js之相同版本后,它工作正常。没有错误。你确定这是Chart.js的问题吗? https://jsfiddle.net/vwh2zsn9/ – Littlee

+0

我的代码是好的,那么问题在别处我用我的代码做了一个jsbin:https://jsbin.com/wehalay/1/edit?html,js,output – DenisMasot

回答

4

问题是这一行:

var ctx = document.getElementById('sexe'); 

你没有ID为“sexe”任何元素的页面

相关问题