3

我正在使用 highcharts 绘制一些图表。它在本地工作得很好,但是当部署到heroku时,我收到这个javascript错误,说Highcharts没有定义。我虽然可能没有预编译 javascript 文件,但我检查了 heroku 日志,发现它确实被预编译了。我也去myapp.herokuapp.com/assets/highcharts.js并在那里找到它。所以我不确定问题是什么。

任何帮助表示赞赏,谢谢。

--- 这是页面的html

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/assets/application-eb12a5437181ffb065f7793b96f720c9.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/application-b5b4fd7bed721cbc4cc70b5a8c8654e9.js" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
....
<div id="container2" style="min-width: 400px; height: 100%; margin: 0 auto"></div><br><br />

<script>
$(function () {
    var chart2;
    $(document).ready(function() {
        chart2 = new Highcharts.Chart({
            chart: {
            renderTo: 'container2',
            type: 'bar',
            height: 450
         },
        title: {
            text: 'Questions'
        },
         subtitle: {
            text: 'number of students with answer'
        },
        xAxis: {
            categories: ["Part3 00:03:31", "Part4 00:03:41", "Part5 00:06:17"],
            labels:{
            useHTML: true}

        },
        yAxis: {
            min: 0,
            allowDecimals: false,
            title: {
                text: 'Number of Students'
            }
        },
        legend: {
            enabled: false,
            layout: 'vertical',
            backgroundColor: '#FFFFFF',
            align: 'left',
            verticalAlign: 'top',
            x: 100,
            y: 70,
            floating: true,
            shadow: true
        },
        tooltip: {
            formatter: function() {
                return ''+
                    this.series.name+': '+ this.y +' student(s)<br>'+question(this.point.x, this.series.name);
            }
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },

        series: [{"name":"Answer 1","data":[11,7,6]},{"name":"Answer 2","data":[4,6,2]},{"name":"Answer 3","data":[5,7,6]},{"name":"Answer 4","data":[0,0,6]}]
    });
4

1 回答 1

-1

我建议使用这个 gem:https ://github.com/market76/lazy_high_charts

它使在 Rails 应用程序中使用 High Charts 变得更加容易。您也可以使用 PhantomJS 导出图形图像服务器端。

于 2013-07-23T19:26:24.770 回答