Chartjs在IE8中不起作用,即使在包含excanvas之后也会出现canvas元素 [英] Chartjs not working in IE8, issue with canvas element even after including excanvas

查看:127
本文介绍了Chartjs在IE8中不起作用,即使在包含excanvas之后也会出现canvas元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直致力于 chartjs
它在IE10中工作正常,但是当我将文档模式更改为IE8时,它会抛出以下错误:

  Object doesn' t支持属性或方法'getContext'line.html,第43行字符2 

我尝试了所有的解决方案建议此处

我包括excanvas.js,但没有运气。

您可以查看演示此处,访问此页面并将文档模式更改为IE8。但是,当我们将浏览器模式和文档模式更改为IE8时,父网站正常工作。请帮我解决这个问题

解决方案

在我的html中我有这个在我的头文件中

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

在我的html中,我有这个给我的身体

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

然后我使用这样的chart.js(用jquery)

  var isOldIE = $(body)。hasClass(oldie); 
var $ canvas = this。$ element.find(canvas);
var canvas = $ canvas [0];
//踢老,即立即创建假帆布
if(isOldIE){
canvas = G_vmlCanvasManager.initElement(canvas);
}
var chartObj = new Chart(canvas.getContext(2d));
//做你的东西,例如
chartObj.Pie(CHARTJS_DATA,CHARTJS_CONFIG);


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

解决方案

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);

这篇关于Chartjs在IE8中不起作用,即使在包含excanvas之后也会出现canvas元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆