Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ie8 chartjs兼容性解决方案 #29

Open
youngwind opened this issue Feb 27, 2016 · 0 comments
Open

ie8 chartjs兼容性解决方案 #29

youngwind opened this issue Feb 27, 2016 · 0 comments

Comments

@youngwind
Copy link
Owner

原因

项目中要用到数据可视化,我选择了Chart.js,确实挺好用的。但是因为Chart.js是用canvas实现的,IE8及以下不支持canvas。官方给出的解决方案在这里
2016-02-27 11 27 32

Attention!

1. chartjs初始化必须在页面刚刚加载的时候完成

如果只是引入excanvas的话,在IE8中还是没法工作。

Initialise charts on load rather than DOMContentReady when using the library, as sometimes a race condition will occur, and it will result in an error when trying to get the 2d context of a canvas.

此处指出,用excanvas的话,初始化chartjs的操作必须在页面刚刚加载的时候就进行,否则程序会在获取canvas上下文的时候出错。
我们去看看excanvas的官方例子

<head>
    <title>ExplorerCanvas Example 1</title>
    <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
    <script type="text/javascript">
        function load() {
            canvas = document.getElementById("cv");
            // ....
        }
    </script>

</head>
<body onload="load();">
    <canvas id="cv" width="400" height="300"></canvas>
</body>

2. 取消动画

New VML DOM elements are being created for each animation frame and there is no hardware acceleration. As a result animation is usually slow and jerky, with flashing text. It is a good idea to dynamically turn off animation based on canvas support. I recommend using the excellent Modernizr to do this.

因为excanvas是采用VML实现的,没有硬件加速功能,所以动画会显示断断续续,并且文字会出现闪烁,因此,如果浏览器不支持canvas的话,最好把动画关闭了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant