我正在尝试为通过Rails生成的JSON数据生成一个样例条形图。
首先,我只想看看我的Rails应用程序是否可以从barchart.html中提供的示例中生成g.raphael github回购。
我在Rails 3.2.11应用程序中使用拉斐尔-rails和g.raphael-rails gem。
当前,当我试图从我的样本代码点击浏览器中的/companies/companies_division时,Firebug抛出以下错误:-
ReferenceError: Raphael is not defined in corresponding to the line of code :-
var r = Raphael("holder")来自这两个gems的文档没有指定需要将任何js文件包含到我的application.js中。
有趣的是,
当我尝试在浏览器中运行下面的示例普通HTML时,我还会得到两个错误。
1.
ReferenceError: Raphael is not defined
F.prototype = Raphael.g;
Reference g.bar.js(line 419) 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>我真的不知道我到底做错了什么。对我可能缺少的东西有什么意见吗?
谢谢。
发布于 2013-08-29 11:52:04
修好了,多亏了我的大四学生的意见。目前,我只是简单地将它们作为JS添加到app/assets/javascripts中,并在我的application.js中要求它们
我需要用正确的顺序定义js。
->样本html代码中的顺序
<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 src="https://raw.github.com/DmitryBaranovskiy/g.raphael/master/g.bar.js" type="text/javascript" charset="utf-8"></script>发布于 2014-02-18 19:54:53
其中一种是使用Rails 4和格斗钢轨 gem:
在application.js语句之前添加到require_tree:
...
//= require raphael/raphael.js
//= require g.raphael/g.raphael.js
//= require g.raphael/g.bar.js // ...and g.pie.js etc
//= require_tree .这个gem通过内部链接到Rafa l和g.Rafaël repos,帮助保持它们的更新。
https://stackoverflow.com/questions/18508741
复制相似问题