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.

4

1 回答 1

2

因为 JavaScript 字符串的外引号是双引号,所以对变量的引用实际上根本不是对变量的引用。您问题中文本的颜色编码应该清楚地表明这一点。

尝试:

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' />";
于 2012-04-10T13:12:39.673 回答