![](/img/trans.png)
[英]I cant get one of my pages to work on Heroku even though it works in my local environment
[英]Highcharts not working on Heroku environment, works on local environment
我正在使用用Highcharts創建的圖表。 它們在我的本地開發環境中工作正常,但在Heroku上,圖表沒有顯示。 div只是空的:
<div id="dashboard_chart_75"></div>
我正在使用lazy_high_charts gem,這是我的application.js
:
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require general.js.erb
//= require_tree .
//= require turbolinks
//= require highcharts/highcharts
//= require highcharts/highcharts-more
//= require social-share-button
//= require ckeditor-jquery
這是生成圖表的代碼:
spider_chart = LazyHighCharts::HighChart.new('graph') do |f|
f.chart(polar: true, type: 'line', height: @height)
f.pane(size: @size)
f.colors(['#C41D21','#1c77bb'])
f.xAxis(
categories: categories.map{ |c| [@survey.id,c.id, c.name] },
tickmarkPlacement: 'on',
lineWidth: 0,
labels: {
style: {
fontSize: '12px',
weight: 'bold',
width: '100%'
},
formatter: %|function() {return '<a href="' + window.location.hostname + '/dashboards/spiders?level=2&survey_id=' + this.value[0] + '&category_id=' + this.value[1] + '">' + this.value[2] + '</a>';}|.js_code }
)
f.yAxis(gridLineInterpolation: 'polygon', lineWidth: 0, min: 0, max: 10,tickInterval: 1, tickWidth: 20)
f.tooltip(enabled: false)
f.series(name: "Gemiddelde van gewenste score", data: norm_scores, pointPlacement: 'on')
f.series(name: "Gemiddelde van huidige score", data: current_scores, pointPlacement: 'on')
f.legend(enabled: @legend, align: 'center', verticalAlign: 'top', y: 10, layout: 'vertical')
end
在生產中我在控制台中看到此錯誤:
Uncaught ReferenceError: Highcharts is not defined at window.onload
哪個指的是這一行:
window.chart_spider_chart = new Highcharts.Chart(options);
可能是什么原因造成的?
你似乎真的有一個簡單的資產版本問題,沒有理由讓highcharts在生產中表現不同。
嘗試清除資產並強制使用以下方法進行預編譯:
$ bundle exec rake assets:clobber
$ RAILS_ENV=production bundle exec rake assets:precompile
然后,添加並提交您的public/assets
文件夾以推送到Heroku。 我遇到了很多麻煩,相信部署預編譯會按預期工作。 有時編譯資產會被竊聽,您需要在預編譯之前更改文件以感知更改。
如果這不起作用
您可能在生產中遇到gem問題,可能是gemfile中的開發塊,或者甚至是=// require_tree .
或者在highcharts lib初始化之前可能插入該代碼的任何其他要求,弄亂腳本的順序會有所幫助(即使你的粘貼代碼沒有反映出來)
嘗試在public
目錄中查找.sprockets-manifest
文件,如果找到則刪除它(它是一個隱藏文件)。 如果您在本地編譯資產並意外地提交了該文件,則可能會阻止Heroku上的資產編譯。
您還可以嘗試通過在config/production.rb
碰撞資產版本來強制重新編譯Heroku資產。 IE將config.assets.version = 1.0
更改為1.1
,然后推送。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.