Mut*_*uma 7 javascript ruby-on-rails highcharts highstock
我在index.html.erb文件中使用我的rails应用程序上的highstocks渲染图表,但是当我尝试加载图表时,我在firebug控制台上收到以下错误,
ReferenceError: HighCharts is not defined
new HighCharts.Chart({
Run Code Online (Sandbox Code Playgroud)
我的index.html.erb文件如下
<div id="quotes_chart", style="width=560px; height:300px;">
<script>
$(function(){
new HighCharts.Chart({
chart : {
renderTo: "quotes_chart"
},
title : {
text: "Daily trades"
},
xAxis : {
type: "datetime"
},
yAxis : {
title: {
text: "Shillings"
}
},
tooltip : {
formatter: function(){
return HighCharts.dateFormat("%B %e, %Y", this.x) + ': ' + "Kshs" + Highcharts.numberFormat(this.y, 2);
}
},
series: [
<% { "Telecommunication" => StockQuote.telecomm, "Agriculture" => StockQuote.agric }.each do |name, prices|
%>
{
name: <%= name %>,
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 2.weeks.ago.to_i * 1000 %>,
data: <%= (2.weeks.ago.to_date..Date.today).map { |date| StockQuote.price_on(date).to_f}.inspect%>
},
<% end %>
]
});
});
</script>
</div>
Run Code Online (Sandbox Code Playgroud)
在我的application.html.erb中如下:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="components/highstock/highstock.js"></script>
<%= javascript_include_tag "jquery-1.11.0.min", "highcharts" %>
Run Code Online (Sandbox Code Playgroud)
在我的app assests/javascripts文件夹中,我有从highcharts.com下载的jquery-1.11.0.min.js和highcharts.js文件
我可能做错了什么?
小智 5
var chart=null;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'bar'
},
title: {
text: '${model.title}'
}
...
Run Code Online (Sandbox Code Playgroud)
将图表设置为 null,因为此错误可能由于您可能不知道的多个声明而发生。假设所有进口都是正确的
您只需加载 Highcharts 一次,而不是加载两次。因此,我建议仅使用:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="components/highstock/highstock.js"></script>
Run Code Online (Sandbox Code Playgroud)
因为 Highstock 包含所有 Highcharts 选项。此外,请注意文件的正确路径,因为它看起来只是它的问题。
| 归档时间: |
|
| 查看次数: |
34090 次 |
| 最近记录: |