dstm2014 2013-12-31 06:01
浏览 68
已采纳

使用PHP将数据库查询结果传递给jQuery Sparkline图表

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

Pie Chart :

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

And I have a PostgreSQL database server.

Suppose I write this query select "Group", COUNT(*) from test group by "Group".

My result will be something like this.

Label   Count
Group1  244
Group2  125

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

I'm using PHP over here.

Someone help me on how to do it.

  • 写回答

2条回答 默认 最新

  • dongqixuan3112 2013-12-31 10:09
    关注

    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

    exemple :

    <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>
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写