How can I get this Javascript / PHP graph to work?

I'm using zingcharrt and it's working great. Here's the code I'm using to generate a graph:

					var chartData={
						 \"type\": \"bar\",  
						 \"background-color\":\"#fff\", 
						 \"plotarea\":{\"background-color\":\"#fff\" },
						 \"title\":{
						 \"text\":\"";
						$briefcase .=stripslashes($graph['measure']);
						 $briefcase .="\",";
						 $briefcase .="\"background-color\":\"#525153\",
						 \"font-color\":\"#ccc\"
						 },
						 
						 \"scale-x\":{
						\"values\":[\"Central Texas\",\"South Central\",\"Florida\",\"Houston /<br>Gulf Coast\", \"Carolinas / <br>Tennessee\", \"Georgia /<br>Alabama\"],
						 \"line-color\":\"#555\",
						 \"line-width\":\"4px\",
						 \"item\":{
							\"color\":\"#000\",\"font-size\":\"12px\"
						},
						
							\"guide\":{
								\"visible\":false
								},
								
								\"tick\":{\"size\":10,
								\"line-width\":3,
								\"line-color\":\"#555\",
								\"placement\":\"outer\"
								} 
						 },
						 
						 \"scale-y\":{
							 \"values\":\"0:1.0000:.1000\",
							 \"multiplier\":true,
							 \"line-color\":\"#555\",
							 \"line-width\":\"4px\"
							
							},
						 
						 \"series\": [
							 {
								 \"values\": [.9188, .9165, .9096, .9059, .8794, .8678 ], 
								 \"background-color-1\":\"#525153\",
								\"background-color-2\":\"#cccccc\" 
							} 
						]
					};
					 window.onload=function(){
					zingchart.render({
					id:'chartDiv_1',
					height:400,
					width:650,
					data:chartData
					  });
					 startclock();
					  };
					</script>";

Open in new window


The challenge is that I have to loop this through a PHP "foreach" statement and need to change the dvi that the graph is point to. I do that on line 50 of the above code like this:

id:'chartDiv_{$count}',

No errors and when you look at the source code, it looks like this:

Working page:

<script>
					var chartData={
						 "type": "bar",  
						 "background-color":"#fff", 
						 "plotarea":{"background-color":"#fff" },
						 "title":{
						 "text":"% 4G devices staying on 4G Network","background-color":"#525153",
						 "font-color":"#ccc"
						 },
						 
						 "scale-x":{
						"values":["Central Texas","South Central","Florida","Houston /<br>Gulf Coast", "Carolinas / <br>Tennessee", "Georgia /<br>Alabama"],
						 "line-color":"#555",
						 "line-width":"4px",
						 "item":{
							"color":"#000","font-size":"12px"
						},
						
							"guide":{
								"visible":false
								},
								
								"tick":{"size":10,
								"line-width":3,
								"line-color":"#555",
								"placement":"outer"
								} 
						 },
						 
						 "scale-y":{
							 "values":"0:1.0000:.1000",
							 "multiplier":true,
							 "line-color":"#555",
							 "line-width":"4px"
							
							},
						 
						 "series": [
							 {
								 "values": [.9188, .9165, .9096, .9059, .8794, .8678 ], 
								 "background-color-1":"#525153",
								"background-color-2":"#cccccc" 
							} 
						]
					};
					 window.onload=function(){
					zingchart.render({
					id:'chartDiv_1',
					height:400,
					width:650,
					data:chartData
					  });
					 startclock();
					  };
					</script><tr><td colspan="2"><div id="chartDiv_1"></div></td></tr><tr><td colspan="2" style="background-color:#525153; color:#ffffff;">% 4G devices staying on 4G Network</td></tr>

Open in new window


...and here's the page where the graph doesn't show up at all:

<script>
					var chartData={
						 "type": "bar",  
						 "background-color":"#fff", 
						 "plotarea":{"background-color":"#fff" },
						 "title":{
						 "text":"% 4G devices staying on 4G Network","background-color":"#525153",
						 "font-color":"#ccc"
						 },
						 
						 "scale-x":{
						"values":["Central Texas","South Central","Florida","Houston /<br>Gulf Coast", "Carolinas / <br>Tennessee", "Georgia /<br>Alabama"],
						 "line-color":"#555",
						 "line-width":"4px",
						 "item":{
							"color":"#000","font-size":"12px"
						},
						
							"guide":{
								"visible":false
								},
								
								"tick":{"size":10,
								"line-width":3,
								"line-color":"#555",
								"placement":"outer"
								} 
						 },
						 
						 "scale-y":{
							 "values":"0:1.0000:.1000",
							 "multiplier":true,
							 "line-color":"#555",
							 "line-width":"4px"
							
							},
						 
						 "series": [
							 {
								 "values": [.9188, .9165, .9096, .9059, .8794, .8678 ], 
								 "background-color-1":"#525153",
								"background-color-2":"#cccccc" 
							} 
						]
					};
					 window.onload=function(){
					zingchart.render({
					id:'chartDiv_1',
					height:400,
					width:650,
					data:chartData
					  });
					 startclock();
					  };
					</script><tr><td colspan="2"><div id="chartDiv_1"></div></td></tr>

Open in new window


I can't see any difference at all, yet the graph doesn't show up.

Any ideas as to what I'm doing wrong?
Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Just pasting either of those generated chart scripts on to a page produces a chart so the javascript is not the problem.

Honestly, I cannot find a single character difference between the two scripts. Only the <tr> markup at the end is different. Is that the intention? Maybe I'm just missing the differences in scripts.

Do all pages containing charts have zingchart.js or zingchart.min.js loading properly?

Could there be css that is hiding the element that holds the chart on the non-working page?

I do that on line 50 of the above code like this:
id:'chartDiv_{$count}',
Actually, you don't. Line 50 says
 id: 'charDiv_1'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bruce GustPHP DeveloperAuthor Commented:
Tom, I got it to work. The issue was not escaping some characters correctly. Once I remedied that, all was golden.

Thanks for weighing in!
Tom BeckCommented:
You're welcome. Glad to hear you got it working.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.