1

I am working with Google Pie Charts API in Javascript. I am using Javascript within PHP. I am passing array elements to API url. But, somehow, I am not getting the required Pie Chart. I think I am messing with the syntax of passing variables to the API url.

This is the code I am using:

function pie(){
?>
<SCRIPT LANGUAGE='Javascript'><!--

piechart();
function piechart() {
var chtdata = new Array(50,50,100,25);       // Array containing values to be mapped

var doc1 =  "<img src='http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:'+chtdata[0]+',50,100,20&chl='r'|'s'|'g'|'h'&chtt='Visitor Details'&chco=ff0000' name='piechart' />";
document.write(doc1);
document.write('Done.');

}
</SCRIPT>
<?php

It would be great if you could point out my mistake. Any help will be appreciated.

1 Answer 1

2

Because the outer quotes on your JavaScript string are double-quotes, the reference to the variable isn't actually a reference to the variable at all. The color-coding of the text right there in your question should show that clearly.

Try:

var doc1 =  "<img src='http://chart.apis.google.com/chart?cht=p3&chs=450x200&chd=t:"+val1+",50,100,20&chl='r'|'s'|'g'|'h'&chtt='Visitor Details'&chco=ff0000' name='piechart' />";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.