2015-08-20 34 views
0

想知道是否有人知道如何將變量放入數組中。我嘗試了下面的技巧。如果它們存在於腳本中,該圖形當前會生成數字。然而它並沒有把變量放在那裏。該變量是值。將數字輸入變量放在JQplot數組(PieChart)中

$(document).keyup(function() { 
 
    var ac = $("#ac1").val(); 
 
    var data = [ //Insert data here 
 
    ['Accomodation', ac], 
 
    ['Retail', 9], 
 
    ['Light Industry', 14], 
 
    ['Out of home', 16], 
 
    ['Commuting', 7], 
 
    ['Orientation', 9] 
 
    ]; 
 
    var plot1 = jQuery.jqplot('pie1', [data], //pie1 is the id for the html section 
 
    { 
 
     seriesDefaults: { 
 
     // Make this a pie chart. 
 
     renderer: jQuery.jqplot.PieRenderer, 
 
     rendererOptions: { 
 
      // Put data labels on the pie slices. 
 
      // By default, labels show the percentage of the slice. 
 
      showDataLabels: true 
 
     } 
 
     }, 
 
     legend: { 
 
     show: true, 
 
     location: 'e' 
 
     } 
 
    } 
 
); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<script language="javascript" type="text/javascript" src="js_plug/jquery.jqplot.min.js"></script> 
 
<script type="text/javascript" src="js_plug/jqplot.pieRenderer.min.js"></script> 
 
<script type="text/javascript" src="js_plug/jqplot.donutRenderer.min.js"></script> 
 

 
<div class="item" id="income_item_1">Item 1 
 
    <input id="ac1" type="text" class="sub_input" /> 
 
</div> 
 
<div class="item" id="income_item_1">Item 1 
 
    <input name="ac2" type="text" class="sub_input"> 
 
</div> 
 
<div class="pie1" id="pie1" style="height:200px;width:500px;"></div>

回答

0

要添加變量到圖表下面的代碼看起來工作。

$(document).keyup(function() { 
 
     var ic = $('#ic').val(); 
 
     var ex = $('#ex').val(); 
 

 

 
     var data = [ //Insert data here 
 
     ['income', ic], 
 
     ['expense', ex] 
 
     ];
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>