2017-03-08 28 views
0

我有一些問題,當我使用anychart與Ajax。 由於anychart的數據依賴於check_box用戶選擇,我必須ajax數據。 圖表的基本形式很好,但選定的數據在圖表上不起作用動態anychart與ajax

這是我的代碼。

<body> 
<div> 
    <input type='checkbox' name='question_id' value='1'> 
    <input type='checkbox' name='question_id' value='2'> 
    <input type='checkbox' name='question_id' value='3'> 
    <input type='checkbox' name='question_id' value='4'> 
    <input type='checkbox' name='question_id' value='5'> 
    <input type='checkbox' name='question_id' value='6'> 
<div> 
<button id='report'>report</button> 
<div id='container'></div> 

</body> 

和我的Ajax和AnyChart的設置如下

<script> 
    $(function() { 
    $('#report').click(function() { 
    $.ajax({ 
     type: 'POST', 
     data: { 
     ids: $("input[name='question_id']:checked").map(function() { 
     return $(this).val(); 
     }).get() 
     }, 



    }); 

    }); 
    }); 

    anychart.onDocumentReady(function() { 
    var dataSet = anychart.data.set(<%= select_data %>); 
    var chart = anychart.column(); 
    ...... 
    ...... 
    chart.container('container'); 
    chart.draw(); 

    }); 
</script> 

我在想,我要重新描繪的AnyChart的,因此AJAX數據可以加載,但我不知道如何使其工作

+0

你能分享一份工作(不工作的樣本)嗎? –

回答

0

看來你不應用更改數據。

當你收到你應該把它應用到圖新數據,也可以這樣做:

數據集= anychart.data.set(newData);

chart.data(newData);

此外,在您的代碼圖表和數據變量是本地的onDocumentReady函數。