Using client-side gauge chart - coldfusion

I am trying to build a client-side gauge chart in CF10. I would like to customize the high and low end of the gauge. But the scaleTo value has no effect. The highest number is always the highest data value. Is there a way to customize the highest number on the gauge?
Here is my cf code:
<cfchart format="html" scalefrom="0" scaleto="40">
<cfchartseries type="gauge">
<cfchartdata item="Series1" value="15">
<cfchartdata item="Series2" value="10">
</cfchartseries>
</cfchart>
And here is the output shown in the browser.

Related

ColdFusion 11 cfchart xAxis format

I am trying to create a simple line chart in ColdFusion 11 and would like to format the xAxis to show a date format like mm-dd-yy instead of the full date/timestamp that is showing by default.
My code is:
<cfchart format="html"
chartwidth="800"
chartheight="400"
xaxistitle="Date"
yaxistitle="Amount"
showlegend="yes"
fontsize="12"
font="Arial"
showMarkers="no"
xAxis=#[{"format"="Date","label":"Date"}]#>
<cfchartseries type="line"
query="getAmounts"
valueColumn="amount"
itemColumn="date">
</cfchart>
The xAxis attribute is giving this error:
You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.
I have tried several different variations of the xAxis attribute with no luck - the documentation is unclear as to what format this should be in. Any help would be appreciated.
The format needs to be something like this...
<cfset myStruct = {"item"={"font-angle"=-90}}/>
And then just set xAxis = "#myStruct#" - you can do that all in the cfchart tag but it is just a little easier to read when the struct gets big. That is the correct format as that is working for us to set the angle of each item. But, I don't know what all of the options are for keys in xAxis. The docs just say "A struct of keys used to style x axis such as format, guide, item, and label."
With that being said, couldn't you just set the correct format to the field "date" in the "getAmounts" query? Then you wouldn't have to deal with it when you output it to the chart.

Selecting A row range from a query of queries

How would I select a specific range of rows using a query of queries?
e.g
<cfquery name="myQuery" maxrows ="20" startrow="12">
SELECT *
FROM previous_query
WHERE row_numer >= 12
</cfquery>
that sort of thing...
This was a tricky one but your problem intrigued me. I think I may have a solution
I wrote a function that delete everything prior to the rows you want and then deletes everything after the rows you want.
the function rowrange() takes 3 parameters.
1. the queryname you are working with.
2. the starting row you want
3. the number of rows you want.
UPDATED: My friend John Whish pointed out that I actually do not need to do the looping to get this to work. Removing the loops makes this much more scalable.
<cfquery name="myQuery">
SELECT *
FROM previous_query
WHERE row_numer >= 12
</cfquery>
<cfset rowRange(myQuery,7,4)>
<cfdump var="#myQuery#">
<cffunction name="rowRange" hint="return a range of rows from a given query">
<cfargument name="qObj" type="query" required="true">
<cfargument name="start" type="numeric" required="true" default="1" hint="The number of the first row to include">
<cfargument name="range" type="numeric" required="true" default="1" hint="The number of rows">
<cfset var i = arguments.start+arguments.range-1>
<cfset arguments.qObj.removeRows(i,arguments.qObj.recordcount-i)>
<cfset arguments.qObj.removeRows(0,arguments.start-1)>
<cfreturn arguments.qObj>
</cffunction>
Doing this natively in CF isn't supported, so you'll have to add a column in your original record set to do the counting for you.
SELECT ..., row_num AS Counter
Row_Num may vary based on your DBMS.

ColdFusion: how to populate livecycle pdf section dynamically using query data

I have a template PDF that has a section that will be laid out like a table. The data will come from a query. So this table will be dynamic, number of rows unknown.
How do I accomplish this using ColdFusion? Is it a combination of creating a template using LiveCycle and creating this section so it is dynamic and then using CFPDF to populate it.
Right now I'm using to populate static fields.
<cfpdfform source="Template.pdf"
destination="Template2.pdf" action="populate">
<cfpdfsubform name="form1">
<cfpdfformparam name="pdf_controlNum" value="123">
<cfpdfformparam name="pdf_ReportDate" value="05/01/2012">
</cfpdfsubform>
</cfpdfform>
I found the solution. It was in this forum:
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_26528588.html
At bottom of thread was this:
2 key points
1. in cf you need to set overwritedata=”yes” in cfpdfform
2. the pdf needs to be a dynamic pdf.
hope this helps others. I don't have a how to blog but if you know of one just let me know. Very handy indeed.
<cfpdfsubform name="details">
<cfpdfsubform name="Table1">
<cfloop from="1" to="#getClientOrderDetails.recordCount#" index="i">
<cfpdfsubform name="Row1" index = "#i#">
<cfpdfformparam name="pdfDescription" value="#getClientOrderDetails.ItemDescription[i]#">
<cfpdfformparam name="pdfItemQuantity" value="#getClientOrderDetails.ItemQuantity[i]#">
<cfpdfformparam name="pdfItemUnitPrice" value="#getClientOrderDetails.ItemUnitPrice[i]#">
</cfpdfsubform>
</cfloop>
</cfpdfsubform>
</cfpdfsubform>
Did you just want to create a PDF File? If so you also have to call in the style sheet after the cfdocument
<cfdocument
format="pdf"
filename = "pdf_file_path\#pdf_controlNum#_#pdf_ReportDate#.pdf"
overwrite = "yes"
marginBottom = ".2"
marginLeft = ".4"
marginRight = ".4"
marginTop = ".2">
<style type="text/css">#import "pdf.css";</style>
QUERY RESULTS TABLES AND CODING HERE ETC
</cfdocument>

cffeed function: show just most recent post?

We have a function to pull RSS feeds and display the post on a ColdFusion page using this code:
<cfset rssUrl = "rss1">
<cffeed action="read" source="#rssUrl#" query="fitness" properties="info">
<cfset rssUrl2 = "rss2">
<cffeed action="read" source="#rssUrl2#" query="nutrition" properties="info">
<cfif #fitness.PUBLISHEDDATE# gt #nutrition.PUBLISHEDDATE#>
<cfset entries="fitness">
<cfelse>
<cfset entries="nutrition">
</cfif>
Output done via:
<cfoutput query="#entries#">
Problem is, the RSS feed has several posts and we only want to show one. Any thoughts on how to get it to pull and display only the most recent post? (We want the feed to have multiple posts, so right now our non ideal solution is to set maximum posts per feed to 1)
cfoutput/query=".." will go over an entire query. If you only want to do the first row, use:
<cfoutput>
Title from row 1: #somequery.title[1]#
</cfoutput>
Basically - array notation on the column. Make sense?
There's nothing wrong with Ray's answer, but here are some other options.
<cfoutput query="#entries#" maxrows="1">
Offers the least disruption to your existing code and, should you decide to change the number of rows displayed (like, via a user setting) it's an easy change.
OR
If you copy the query object rather than the query name (which isn't actually a copy but a copy by reference)
<cfset entries = fitness>
instead of
<cfset entries = "fitness">
you can do this
<cfoutput>
#entries.columnName1#
#entries.columnName2#
<!--- etc. --->
</cfoutput>
which will, by default, display only the first row of the query.

Calculate and Display Disk Usage

Using CF8, I want to produce a graph that displays the disk usage, in megabytes, per client. The clients are the directories within D:\inetpub\sites.
I've looked through the docs and found examples only using DB queries. I am using <cfdirectory> to get a list of directories.
<cfdirectory action="list"
directory="#expandPath("../../")#"
name="webDirectories">
<cfquery name="getInfo" dbtype="query">
select sum(size) as total, name
from webDirectories
group by name
</cfquery>
<h1>Web Server Disk Usage Analysis</h1>
<!--- Bar graph, from Query of Queries --->
<cfchart format="flash"
xaxistitle="Client"
yaxistitle="Disk Usage">
<cfchartseries type="bar"
query="getInfo"
itemcolumn="name"
valuecolumn="size">
<cfoutput query="getInfo">
<cfchartdata item="#name#" value=#Round(total/1000)*1000#>
</cfoutput>
</cfchartseries>
</cfchart>
I would like to have the clients listed in the x-axis and usage on the y-axis. How can I achieve this?
Your chart code is wrong. I changed it to this, and it worked for me:
<h1>Web Server Disk Usage Analysis</h1>
<!--- Bar graph, from Query of Queries --->
<cfchart format="flash"
xaxistitle="Client"
yaxistitle="Disk Usage">
<cfchartseries type="bar"
query="getInfo"
itemcolumn="name"
valuecolumn="total" />
</cfchart>
If you want to do your round(total/100)*1000, you can just massage the query further before feeding it into the chart.