最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chartjs not working in IE8, issue with canvas element even after including excanvas - Stack Overflow

programmeradmin1浏览0评论

I have been working on chartjs. It works fine in IE10 but when I change the document mode to IE8 it throws the below error

 Object doesn't support property or method 'getContext'  line.html, line 43 character 2

I tried all the solutions suggested here

I included excanvas.js but no luck.

You can check the demo here , visit this page and change the document mode to IE8. But the parent site works fine when we change browser mode and document mode to IE8. Please help me fix this issue

I have been working on chartjs. It works fine in IE10 but when I change the document mode to IE8 it throws the below error

 Object doesn't support property or method 'getContext'  line.html, line 43 character 2

I tried all the solutions suggested here

I included excanvas.js but no luck.

You can check the demo here , visit this page and change the document mode to IE8. But the parent site works fine when we change browser mode and document mode to IE8. Please help me fix this issue

Share Improve this question edited Jul 21, 2015 at 3:03 Vignesh Subramanian asked Aug 19, 2013 at 10:14 Vignesh SubramanianVignesh Subramanian 7,30914 gold badges96 silver badges158 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

in my html i have this in my header

<!--[if lt IE 9]>
<script type="text/javascript" src="../shared/js/excanvas/r73/excanvas.js?v=${BUILD.TAG}"></script>
<![endif]-->

in my html i have this for my body

<!--[if lt IE 9]>
<body class="oldie">
<![endif]-->
<!--[if (gte IE 9)|!(IE)]>
<body>
<!--<![endif]-->

then i use the chart.js like so (with jquery)

var isOldIE = $("body").hasClass("oldie");
var $canvas = this.$element.find("canvas");
var canvas = $canvas[0];
// kick old ie into creating fake canvas straight away
if(isOldIE) {
   canvas = G_vmlCanvasManager.initElement(canvas);
}
var chartObj = new Chart(canvas.getContext("2d"));
// do your stuff eg
chartObj.Pie(CHARTJS_DATA, CHARTJS_CONFIG);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论