[英]How to feed dynamic data to static jquery function?
My source code is here below. 我的源代码在下面。 The chart it creates made by using chartist.js .
它使用chartist.js创建的图表。
<html>
<head>
<link rel="stylesheet" href="chartist.min.css">
</head>
<body>
<h3>Chartist Test</h3>
<br>
<div id="ct-chart5" class="ct-perfect-fourth"></div>
<script src="chartist.min.js"></script>
<script src="jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function(){
var data = {
series: [5, 3, 4]
};
var sum = function(a, b) { return a + b };
new Chartist.Pie('#ct-chart5', data, {
labelInterpolationFnc: function(value) {
return Math.round(value / data.series.reduce(sum) * 100) + '%';
}
});
});
</script>
</body>
</html>
There is a var called data inside scripts tags below. 下面的脚本标签中有一个称为数据的变量。 But the thing is it has predefined values and chat is creating by those static values.
但事实是它具有预定义的值,而聊天是由这些静态值创建的。 How i can post some dynamic data into that variable?
我如何将一些动态数据发布到该变量中? lets say we have some data retrieving from mysql db.
可以说我们有一些从mysql db检索的数据。 i want to know how to feed those retrieving data into the predefined variable dynamically.
我想知道如何将那些检索数据动态地输入到预定义变量中。
I think you are talking about ajax calls, well you declare that variable globally make and ajax call, get dynamic data and update the variable. 我认为您是在谈论ajax调用,因此您可以全局声明该变量进行make和ajax调用,获取动态数据并更新该变量。
var data;
//some code
$.ajax({
url: some_URL,
data: some_data,
dataType: some_datatype
//other options,
success:function(jqXHR){
data=jqXHR;//assuming jqXHR is the dynamic data
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.