我正在尝试为通过 Rails 生成的 JSON 数据生成示例条形图。
首先,我只是想看看我的 Rails 应用程序是否可以从g.raphael github repo中提供的示例生成 barchart.html 。
我在我的 Rails 3.2.11 应用程序中使用raphael-rails和g.raphael-rails gem。
目前,当我尝试从我的示例代码中点击浏览器中的 /companies/company_division_stats 时,Firebug 会引发以下错误:-
ReferenceError: Raphael is not defined in corresponding to the line of code :-
var r = Raphael("holder")
这两个 gem 的文档没有指定需要将任何 js 文件包含到我的 application.js 中。
有趣的是,
当我尝试在浏览器中运行下面的示例纯 HTML 时,我也收到两个错误。
1.
ReferenceError: Raphael is not defined
F.prototype = Raphael.g;
Reference g.bar.js(line 419)
2.
TypeError: r.barchart is not a function
示例 HTML:-
<!--<!doctype html>-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>g·Raphaël Static Bar Charts</title>
<link rel="stylesheet" href="css/demo.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="css/demo-print.css" type="text/css" media="print" charset="utf-8">
<!-- Throws same error when using the raphael and g.raphael gem-->
<script src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/g.bar.js" type="text/javascript" charset="utf-8"></script>
<script src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/raphael-min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/g.raphael.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var r = Raphael("holder"),
data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
r.text(160, 10, "Single Series Chart").attr(txtattr);
// r.text(480, 10, "Multiline Series Chart").attr(txtattr);
// r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
// r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "soft"});
// r.barchart(330, 10, 300, 220, data1);
// r.barchart(10, 250, 300, 220, data2, {stacked: true});
// r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
};
</script>
</head>
<body class="raphael" id="g.raphael.dmitry.baranovskiy.com">
<div id="holder"></div>
<p>
Demo of <a href="http://g.raphaeljs.com/">g·Raphaël</a> JavaScript library.
</p>
</body>
</html>
我真的不确定我到底做错了什么。关于我可能缺少的任何输入?
谢谢你。