1
私はWebアプリケーションを作成しており、値が5秒ごとに更新されるグラフを描画したいと考えています。私はグローバルな価値を作り出そうとしましたが、チャートを最初に描画してから、自分のajaxコールからデータを取得するため、うまくいきませんでした。関数からJSONデータを取得してChart JSに値を与える
overview_p.php:
$(document).ready(function(){
getChartInfo();
});
setInterval(function(){ getChartInfo() }, 5000);
function getChartInfo()
{
$.ajax({
type: 'post',
url: 'php/classes/dash/overview_c.php',
data: "type=stat1&user_id=<?php echo $_SESSION['user_id'];?>",
dataType: 'json',
success: function(responseStat1){
var statHour1 = 0;
$.each(responseStat1, function(index){
statHour1 += responseStat1[index].hours;
});
$('.statHour1').html(statHour1 + ' uur');
},
error: function(error){
console.log(error);
}
})
}
overview_c.php:唯一の他の選択肢がにあるので、あなたは成功関数内自分のチャートを描画する必要があり
<?php
class Overview{
public function getStat1(){
$json_getStat1[] = array('hours' => '2');
}
print json_encode($json_getStat1);
}
}
}
$overview = new Overview();
switch($_POST['type']){
case 'stat1':
$overview->getStat1();
break;
}
?>
グラフはどのくらい正確に描かれていますか? – adeneo