解析迷你图中的动态数据 [英] Parsing Dynamic Data in Sparklines
问题描述
我想解析迷你图中的动态数据.
我的代码:
I want to parse dynamic data in sparklines.
My code:
$(".daily-visitors").sparkline([1,5,5.5,5.4,5.8,6,8,9,13,12,10,11.5,9,8,5,8,9], {
type: 'line',
width: '100%',
height: '55',
lineColor: '#ff4e50',
fillColor: '#ffd2d3',
lineWidth: 2,
spotColor: '#a9282a',
minSpotColor: '#a9282a',
maxSpotColor: '#a9282a',
highlightSpotColor: '#a9282a',
highlightLineColor: '#f4c3c4',
spotRadius: 2,
drawNormalOnTop: true
});
我想使用 PHP 从 MYSQL 中获取动态数据.
I want dynamic data from MYSQL by using PHP.
推荐答案
我建议使用一个新的 php 文件,您可以在其中使用 POST 请求获取 JSON 数据.示例查询:
I suggest a new php file where you'd be getting JSON data from using POST request. Example query:
$query = mysql_query("SELECT daily_visitors FROM stats ORDER BY when DESC LIMIT 30");
然后您准备好显示迷你图.获取数组后,您可以执行以下操作并以 JSON 格式返回数据:
Then you prepare it for sparklines to display. After fetching the array you can do something like this and return the data in JSON format:
echo json_encode($data);
这将等同于这样的事情:
Which would be equivalent to something like this:
[1,5,5.5,5.4,5.8,6,8,9,13,12,10,11.5,9,8,5,8,9]
然后您可以从您的网站 POST 请求此数据:
You can then POST request this data from your website:
$.post("url to your php file", { examplePostArgument:"test" }, function(data){
$(".daily-visitors").sparkline(data, {
type: 'line',
width: '100%',
height: '55',
lineColor: '#ff4e50',
fillColor: '#ffd2d3',
lineWidth: 2,
spotColor: '#a9282a',
minSpotColor: '#a9282a',
maxSpotColor: '#a9282a',
highlightSpotColor: '#a9282a',
highlightLineColor: '#f4c3c4',
spotRadius: 2,
drawNormalOnTop: true
});
});
这个 examplePostArgument 将可以使用这个超全局数组在你的 PHP 文件中访问:
This examplePostArgument will be accessible in your PHP file using this superglobal array:
$_POST["examplePostArgument"];
这篇关于解析迷你图中的动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!