2013-10-17 2 views
0

안녕하세요. Jquery 플러그인을 만드는 방법에 대한 지침을 따랐습니다. 내 페이지가 jquery 코드로 매우 커지면서이를 처리하고 싶습니다. 보다 나은. ReferenceError 오류가 발생합니다 : myGauge가 정의되지 않았습니다.jquery 첫 번째 플러그인을 만들지 않습니다. referenceError 함수가 정의되지 않았습니다.

여기 여기

<!DOCTYPE HTML> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Highcharts Example</title> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> 
      <script src="http://code.highcharts.com/highcharts.js"></script> 
      <script src="http://code.highcharts.com/highcharts-more.js"></script> 
      <script src="http://code.highcharts.com/modules/exporting.js"></script> 
      <script src="js/myFunction.js"></script>    
<script type="text/javascript"> 
$(document).ready(function(){ 
$(function() { 
myGauge(); 
}); 
}); 
</script> 
</head> 
<body> 
<div id="container" style="min-width: 310px; max-width: 400px; height: 300px; margin: 0 auto"></div> 
</body> 
</html> 

그대로 myFunction.js이

(function($) { 

$.fn.myGauge = function() { 

    $('#container').highcharts({ 

    chart: { 
     type: 'gauge', 
     alignTicks: false, 
     plotBackgroundColor: null, 
     plotBackgroundImage: null, 
     plotBorderWidth: 0, 
     plotShadow: false 
    }, 

    title: { 
     text: 'test' 
    }, 

    pane: { 
     startAngle: -150, 
     endAngle: 150 
    },   

    yAxis: [{ 
     min: 0, 
     max: 200, 
     lineColor: '#339', 
     tickColor: '#339', 
     minorTickColor: '#339', 
     offset: -25, 
     lineWidth: 2, 
     labels: { 
      distance: -20, 
      rotation: 'auto' 
     }, 
     tickLength: 5, 
     minorTickLength: 5, 
     endOnTick: false 
    }, { 
     min: 0, 
     max: 124, 
     tickPosition: 'outside', 
     lineColor: '#933', 
     lineWidth: 2, 
     minorTickPosition: 'outside', 
     tickColor: '#933', 
     minorTickColor: '#933', 
     tickLength: 5, 
     minorTickLength: 5, 
     labels: { 
      distance: 12, 
      rotation: 'auto' 
     }, 
     offset: -20, 
     endOnTick: false 
    }], 

    series: [{ 
     name: 'Speed', 
     data: [80], 
     dataLabels: { 
      formatter: function() { 
       var kmh = this.y, 
        mph = Math.round(kmh * 0.621); 
       return '<span style="color:#339">'+ kmh + ' km/h</span><br/>' + 
        '<span style="color:#933">' + mph + ' mph</span>'; 
      }, 
      backgroundColor: { 
       linearGradient: { 
        x1: 0, 
        y1: 0, 
        x2: 0, 
        y2: 1 
       }, 
       stops: [ 
        [0, '#DDD'], 
        [1, '#FFF'] 
       ] 
      } 
     }, 
     tooltip: { 
      valueSuffix: ' km/h' 
     } 
    }] 

}, 
// Add some life 
function(chart) { 
    setInterval(function() { 
     var point = chart.series[0].points[0], 
      newVal, inc = Math.round((Math.random() - 0.5) * 20); 

     newVal = point.y + inc; 
     if (newVal < 0 || newVal > 200) { 
      newVal = point.y - inc; 
     } 

     point.update(100);//(newVal); 

    }, 3000); 

}); 

} 

}(jQuery)); 

답변

0

당신은 단지 myGauge()를 호출 할 수 없습니다 내 페이지입니다.

jQuery 플러그인으로 변경 했으므로 jQuery 객체를 추가해야합니다.
예 : $("#test").myGauge()

관련 문제