asp.net - graphaeljs错误

标签 asp.net asp.net-mvc-4 charts graphael

我正在使用 graphaeljs 库在 ASP.NET MVC 4 上显示图表

我从 graphaeljs 网站复制了这段代码

 <script src="scripts/raphael.js"></script>
            <script src="scripts/g.raphael-min.js"></script>
            <script src="scripts/g.bar-min.js"></script>
            <script>
                window.onload = function () {
                    var r = Raphael("holder"),
                        fin = function () {
                            this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
                        },
                        fout = function () {
                            this.flag.animate({ opacity: 0 }, 300, function () { this.remove(); });
                        },
                        fin2 = function () {
                            var y = [], res = [];
                            for (var i = this.bars.length; i--;) {
                                y.push(this.bars[i].y);
                                res.push(this.bars[i].value || "0");
                            }
                            this.flag = r.popup(this.bars[0].x, Math.min.apply(Math, y), res.join(", ")).insertBefore(this);
                        },
                        fout2 = function () {
                            this.flag.animate({ opacity: 0 }, 300, function () { this.remove(); });
                        },
                        txtattr = { font: "12px sans-serif" };

                    r.text(160, 10, "Single Series Chart").attr(txtattr);
                    r.text(480, 10, "Multiline Series Stacked Chart").attr(txtattr);
                    r.text(160, 250, "Multiple Series Chart").attr(txtattr);
                    r.text(480, 250, "Multiline Series Stacked Chart\nColumn Hover").attr(txtattr);

                    r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]]).hover(fin, fout);
                    r.hbarchart(330, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true }).hover(fin, fout);
                    r.hbarchart(10, 250, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]]).hover(fin, fout);
                    var c = r.barchart(330, 250, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true, type: "soft" }).hoverColumn(fin2, fout2);
                };
            </script>

但是当我在浏览器中运行时,会出现此消息

Uncaught TypeError: Cannot read property 'x' of undefined raphael.js:11
c._engine.create raphael.js:11
c raphael.js:9
window.onload (index):92

我不知道我做错了什么,我完全按照原样使用了这些库。你能告诉我,我可能犯了什么错误吗?

最佳答案

抱歉,我没有发现您发布的代码有任何问题。 我做了一个fiddle为你。

这显然是 raphael.js 文件的问题。

请务必在 body 标记中包含 class="raphael",并在 div 中包含 id="holder"

如果失败,请尝试重新下载 raphael.js

关于asp.net - graphaeljs错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21070355/

相关文章:

asp.net - 如何以及在何处调用 Database.EnsureCreated 和 Database.Migrate?

asp.net - 获取位于 GridView 中模板字段内的超链接的文本

asp.net-mvc-4 - ASP.NET Entity Framework 能否自动生成数据注释?

从 MVC Razor 中的数据库获取数据时的 LINQ 查询性能问题

flutter - 如何更改图表的标签颜色

flutter - 如何防止指标点在Chart_flutter中的setState()上消失

javascript - 如何使用 D3 和 JS 字典制作多个饼图?

c# - 将 Javascript 添加到 C# 中的用户控件

asp.net - “maintainScrollPositionOnPostBack=” true “” 不适用于谷歌浏览器

.net - MVC4 - Facebook(登录失败。服务登录失败。)