6 Replies - 3128 Views - Last Post: 27 March 2012 - 02:11 PM Rate Topic: -----

#1 rikkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-March 12

display CF chart without using a database query?

Posted 26 March 2012 - 06:12 PM

I have been trying to figure out a way to have a visitor fill out a simple form.
The form variables will then be used within the CF chart tag to display a chart.
Can this be done without a database query?
Is This A Good Question/Topic? 0
  • +

Replies To: display CF chart without using a database query?

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1947
  • View blog
  • Posts: 3,488
  • Joined: 13-January 08

Re: display CF chart without using a database query?

Posted 27 March 2012 - 05:40 AM

Welcome to DIC rikkp!

To answer your question, yes and rather easily. I'm assuming your question is actually asking how you can use CFCHARTSERIES to populate your chart with data when the data you have is in a submitted form, right?

If so, the solution is to build a query object and populate it with the form data. For that you'll need to use the QueryNew() function (along with a couple of other query related CF functions).

Have a look at that function and then see if the solution doesn't present itself to you. :)

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 rikkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-March 12

Re: display CF chart without using a database query?

Posted 27 March 2012 - 09:15 AM

When I hard code the values in the code shown here, it displays the chart fine.
The problem is I need to set dynamic values for each Source with variables submited by a form.
After a week of researching this topic, I am no closer to a solution. Any suggestions would be appreciated.
Thanks!

<cfset Source = structNew() >
<cfset Source["Toilet"] = 12.5>
<cfset Source["Rain"] = 7.3>
<cfset Source["PetDish"] = 3>
<cfset Source["Faucet"] = 14>
<cfset Source["Milk"] = 6.1>

<cfchart chartheight="400" chartwidth="600" yaxistitle="PH Level" title="Your Local PH Level Water Test " fontsize="10" show3d="yes" gridlines="5" 

showmarkers="yes" showxgridlines="yes" >
 <cfchartseries type="horizontalbar" seriescolor="##FF0000" >
<cfloop list="#ArrayToList( StructSort(Source, "numeric", "desc") )#" index="key" >

<cfchartdata item="#key#" value="#Source[key]#" >
</cfloop>
</cfchartseries>
</cfchart>



Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1947
  • View blog
  • Posts: 3,488
  • Joined: 13-January 08

Re: display CF chart without using a database query?

Posted 27 March 2012 - 09:59 AM

Okay...so what you're wanting to do work with then is this part:
<cfset Source = structNew() >
<cfset Source["Toilet"] = 12.5>
<cfset Source["Rain"] = 7.3>
<cfset Source["PetDish"] = 3>
<cfset Source["Faucet"] = 14>
<cfset Source["Milk"] = 6.1>



This is actually not all that hard once you know a trick or two. If you submit a form in CF and look in your debug output you'll see something like this where it displays the form scope:
Posted Image
You'll notice the highlighted part is a form field you DIDN'T submit that's called fieldnames. Fieldnames is a comma delimited list of all the form fields you DID submit though. So, with that comma delimited list, you can do a CFLOOP using that list and get the field name on each iteration like so:
<cfloop list="#form.fieldnames#" index="formVarName">
   <cfoutput>formVarName: [#formVarName#]<br>
</cfloop>


So, if you run that, you'll see an output block with each of the form field names you just submitted. Those (if you like) can be used to substitute for "toilet", "rain", etc in your example. That said, you still need to fill the other side of those cfsets by getting the form value for each field. Now, you can use the Evaluate() function and that'll work fine...but I find that it's a pain in the ass. I prefer getting the value like so:
<cfset formValue = Form["#formVarName#"]>

If you put your cfsets inside the cfloop example I gave you above, you can pull both the name of the form fields submitted and their respective values and then build your struct dynamically as you loop over it.

That ought to be enough to get you on your way. If you have any other questions or problems, post back here.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#5 rikkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-March 12

Re: display CF chart without using a database query?

Posted 27 March 2012 - 12:27 PM

Thanks Criag 328,

I think you may be onto something with the comma delimited Fieldnames variable that CF creates.
I will play with it and let you know how I made out.
Was This Post Helpful? 0
  • +
  • -

#6 rikkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-March 12

Re: display CF chart without using a database query?

Posted 27 March 2012 - 01:57 PM

I GET THE ERROR (Element FIELDNAMES is undefined in FORM)
Below is the code from the form and action page.


<form action="chart02.cfm" method="get">

<input type="text" name="toilet">Toilet<br /><br />
<input type="text" name="rain">Rain<br /><br />
<input type="text" name="petdish">Pet Dish<br /><br />
<input type="text" name="faucet">Faucet<br /><br />
<input type="text" name="milk">Milk<br /><br />
<input name="submit" type="submit">
</form>

-----------------
<cfloop list="#form.fieldnames#" index="formVarName">

<cfoutput>formVarName: [#formVarName#] <br /></cfoutput>
</cfloop>




I tried this code with the cfoutput tag before the cfloop,within the cfloop and no matter what I still get Element FIELDNAMES is undefined in FORM
Was This Post Helpful? 0
  • +
  • -

#7 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1947
  • View blog
  • Posts: 3,488
  • Joined: 13-January 08

Re: display CF chart without using a database query?

Posted 27 March 2012 - 02:11 PM

Try changing the form method value to "post" instead of "get" and see what that does for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1