Any Javascript geniuses in the area??

by 8 replies
9
I have been tearing out my hair trying to figure this out...

The following script is meant to generate a fusionchart Pie3d Chart. It works great as shown here.

<script language="JavaScript">

var chart1 = new FusionCharts("http://www.help-my-finances.com/Prototype/testMSG/fusionchart/Pie3D.swf", "chart1Id", "700", "500", "0", "1");

chart1.setDataXML("<chart caption='Monthly Budget Expenses' palette='2' animation='1' formatNumberScale='0' numberPrefix='$' pieSliceDepth='30' startingAngle='145'><set label='Housing' value='1386' /><set label='Food' value='11' /><set label='Auto' value='11' /><set label='Insur.' value='11' /><set label='Debt' value='11' /><set label='Enter.' value='11' /><set label='Clothing' value='11' /><set label='Savings' value='11' /><set label='Medical' value='11' /><set label='Childcare' value='11' /><set label='Misc' value='11' /></chart>");

chart1.render("chart1div");

</script>




The problem comes when I want to substitute a variable for one of the hardcoded or defined values in the middle statement above. For example, setting the value='11' to value=$test1 for example.

Any bright ideas before I have to throw myself off this chair?

Talltom
#programming #area #geniuses #javascript
  • Where are you getting the variable $test1 from? Are you generating this code with PHP and trying to substitute the PHP variable $test1 in the Javacript code?
  • Well, right now its being defined in php. I also will have situations where I will be using smarty variables.
  • If you're trying to insert a PHP value into the javascript definition you'll need to be sure to wrap the variable in a PHP tag or it won't get recognized.

    So, instead of: value=$test1
    You need: value='<?php echo $test1; ?>'
    • [ 1 ] Thanks
  • IT WORKED!!!!!

    Jeepers - a simple solution to a huge PITA

    Thanks
    • [1] reply
    • Easier would be to use the PHP classes that come with Fusion Charts.
  • Glad you got it working.
  • Well, partly.

    In a pure php file, it works great.

    However, My main program is using the Smarty template engine, and I am still struggling with inserting variables there.

    Talltom
  • Do you have a snippet of your current smarty code that works with the javascript insert? If you paste it here, we can get that working too.

Next Topics on Trending Feed