2014-05-19 204 views
2

我试图使用gauge.js插件与我的Rails应用4,但我发现了一个遗漏的类型错误:未定义是不是在我的控制台时,一个功能错误试图击中主页。遗漏的类型错误:未定义是不是一个函数gauge.js

下面是我在的application.js

//= require jquery 
//= require gauge.min.js 

这里就是我在我的的index.html观点:

<script> 
jQuery(document).ready(function(){ 
    var opts = { 
    lines: 12, // The number of lines to draw 
    angle: 0.15, // The length of each line 
    lineWidth: 0.44, // The line thickness 
    pointer: { 
     length: 0.9, // The radius of the inner circle 
     strokeWidth: 0.035, // The rotation offset 
     color: '#000000' // Fill color 
    }, 
    limitMax: 'false', // If true, the pointer will not go past the end of the gauge 
    colorStart: '#6FADCF', // Colors 
    colorStop: '#8FC0DA', // just experiment with them 
    strokeColor: '#E0E0E0', // to see which ones work best for you 
    generateGradient: true 
    }; 
    var target = document.getElementById('foo'); // your canvas element 
    var gauge = new Gauge(target).setOptions(opts); // create sexy gauge! 
    gauge.maxValue = 3000; // set max gauge value 
    gauge.animationSpeed = 32; // set animation speed (32 is default value) 
    gauge.set(1250); // set actual value 
}) 
</script> 

我搜索这个错误,发现这是一个脚本以错误的顺序加载的问题,所以我想知道这是否与Rails 4 turbolinks有关,因为我的应用程序的其他部分加载了JS。

+0

我读过有有这个问题,由于进口.min.js,而不是人。 JS。也许你面临同样的问题。你可以尝试导入.js而不是.min吗? – FabKremer

+0

仍然与它的.coffee版本相同的问题:Uncaught TypeError:undefined不是一个函数gauge.js – beaconhill

回答

3

以前我有:

<div id="foo"></div> 

它需要:

<canvas id="foo"></canvas> 
相关问题