0

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.

Unknown User
  • 3,598
  • 9
  • 43
  • 81

2 Answers2

0

suppose we have result in $result array. So, you can replace 2 with echo $result['Label'] and 1 with echo $result['Count'] but in single inverted comma like below

'<?php echo $result['Label'] ?>'

Naresh Walia
  • 2,012
  • 2
  • 16
  • 16
0

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.

Tosx
  • 606
  • 3
  • 8
  • I wanted to store that `244` and `125` to two javascript variables. – Unknown User Dec 31 '13 at 11:46
  • When you have it in an array it's easy to do for exemple : var value1 = array[0]; // 244 var value2 = array[1]; // 125 After you can use it as you want. This is what you want ? – Tosx Dec 31 '13 at 12:08
  • But I'm calling it through `ajax`. Through `ajax` I run this `function(result) {$('#msg').html(result)}` which returns the result of the `PostgreSQL` query result. Help me to assign returned value to a two javascript variables. – Unknown User Dec 31 '13 at 12:20
  • Look at this i think it's similar : http://stackoverflow.com/questions/13648995/how-to-grab-return-value-from-an-ajax-call – Tosx Dec 31 '13 at 12:26
  • Sorry bro. That didn't help me. Shall I create a new post for a better understanding? – Unknown User Dec 31 '13 at 12:30
  • let's try one more time :p so you call a ajax script it return your reponse and you want to put that response into two js variables ? – Tosx Dec 31 '13 at 12:40
  • Here's the [**link**](http://stackoverflow.com/questions/20857539/store-each-value-of-a-ajax-query-result-to-javascript-variables) for the post :) – Unknown User Dec 31 '13 at 12:41