使用PHP将数据库查询结果传递给jQuery Sparkline Charts [英] Passing Database Query Results to jQuery Sparkline Charts Using PHP

查看:122
本文介绍了使用PHP将数据库查询结果传递给jQuery Sparkline Charts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用jquery-sparline创建了PIE图表.

I've created a PIE chart using jquery-sparline.

饼图:


 $(".sparkline").sparkline([2,1], {
                type: 'pie',
                width: '100',
                height: '100',
                sliceColors: ['#F2441D','#fff'],
                borderWidth: 3,
                borderColor: '#F2441D'});

我有一个PostgreSQL数据库服务器.

And I have a PostgreSQL database server.

假设我写此查询select "Group", COUNT(*) from test group by "Group".

我的结果将是这样.


Label   Count
Group1  244
Group2  125

现在,我需要在javascript代码中将其替换为值21.

Now I need to replace these with value 2 and 1 in the javascript codes.

我在这里使用PHP.

有人帮我做这件事.

推荐答案

我不确定,但是我认为您将需要在html balise中打印您的值(以隐藏文件为例),然后使用javascript检索它:document.getElementById

I'm not sure but i think you will have to print you value in html balise (hidden filed for exemple) and retrieve it using javascript : document.getElementById

示例:

<input type="hidden" id="valueForJs" value="244-125">
<script>
   var obj = document.getElementById("valueForJs").value;
   var array = obj.split("-");

   alert('value = ' + array[0] + ' ' + array[1]);
   // now you have your 2 value and you can use it in your script below...
</script>

您也可以将值放在spanhide这个范围中,例如,但是我认为输入会更干净.

You can also put the value in a span and hide this span for exemple, but i think input will be cleaner.

这篇关于使用PHP将数据库查询结果传递给jQuery Sparkline Charts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆