お世話になります。
初歩的な質問で申し訳御座いません。
googleで検索して20件ほど確認したものの解決に至らなかったため質問させてください。
目的
Chart.jsを使って折れ線グラフを表示したい
動作環境
Chrome(ver.64.0.3282.140)64bit
Chart.js(Version: 2.7.1)
Windows 7 Pro
前提
Chart.bundle.min.jsはhtmlファイルと同一フォルダにある
Test.jsはhtmlファイルと同一フォルダにある
試してみたこと
Chart.bundle.min.jsをChart.min.jsにしても同様のエラーが出る
Chart.bundle.min.jsをChart.jsにしても同様のエラーが出る
コード
HTML
1<!DOCTYPE html> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<script src="Chart.bundle.min.js"></script> 6<script src="Test.js"></script> 7<title>グラフテスト</title> 8</head> 9<body> 10<canvas id="myChart"></canvas> 11</body> 12</html>
JavaScript
1var ctx = document.getElementById('myChart').getContext('2d'); 2var myChart = new Chart(ctx, { 3 type: 'line', 4 data: { 5 labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'], 6 datasets: [{ 7 label: 'apples', 8 data: [12, 19, 3, 17, 6, 3, 7], 9 backgroundColor: "rgba(153,255,51,0.4)" 10 }, { 11 label: 'oranges', 12 data: [2, 29, 5, 5, 2, 3, 10], 13 backgroundColor: "rgba(255,153,0,0.4)" 14 }] 15 } 16});
エラーメッセージ
Cannot read property 'getContext' of null
googleで検索してみると、canvasのidが設定されていない、というのが見つかりますが
上記にもある通り、idは正しく設定されています。
お手数おかけしますが、よろしくお願いします。
以上です。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/07 02:18