Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send a CFCHART via CFMAIL

Status
Not open for further replies.

firepwr

IS-IT--Management
May 22, 2006
31
US
Does anyone know if it's possible to send a CFCHART via CFMAIL? All kinds of people are asking this but no one seems to have an answer.... I tried modifying the example from the online docs to what's below (comments removed) but all I receive is an email with a red "x" in it and the 5 data records in a grid....

Code:
<cfquery name="GetSalaries" datasource="cfdocexamples">
	SELECT Departmt.Dept_Name, 
	Employee.Dept_ID, 
	Employee.Salary
	FROM Departmt, Employee
	WHERE Departmt.Dept_ID = Employee.Dept_ID
</cfquery>

<cfquery dbtype = "query" name = "DataTable">
	SELECT 
	Dept_Name,
	AVG(Salary) AS avgSal,
	SUM(Salary) AS sumSal
	FROM GetSalaries
	GROUP BY Dept_Name
</cfquery>

<cfloop index = "i" from = "1" to = "#DataTable.RecordCount#">
	<cfset DataTable.sumSal[i] = Round(DataTable.sumSal[i]/1000)*1000>
	<cfset DataTable.avgSal[i] = Round(DataTable.avgSal[i]/1000)*1000>
</cfloop>

<CFMAIL FROM="My Email Address"
	TYPE="HTML"
	TO="My Email Address"
	SUBJECT="TEST">

<h1>Employee Salary Analysis</h1> 

<cfchart format="jpg" 
	xaxistitle="Department" 
	yaxistitle="Salary Average"
	show3D="yes"> 

	<cfchartseries type="bar" 
		query="DataTable" 
		itemcolumn="Dept_Name" 
		valuecolumn="avgSal">

		<cfchartdata item="Facilities" value="35000">

	</cfchartseries>

</cfchart> 

</cfmail>

I did try writing everything to a CFSAVECONTENT variable too but with the same result....

Has anyone ever done this before? Is it possible? It seems pretty short sighted of Macromedia/Adobe to allow you to use these cool charts but not be able to convert them to .PDF or email them.... Or is there something I'm missing?
 
Sounds to me like CFCHART is another one of those CFGRID-style applet/ActiveX objects. For obvious reasons, this won't render in an email.

What's the HTML source of the email say? Is the red "X" actually an IMG tag that points to some weird file name? If so, you're looking at dynamically generated images of the chart, and they won't render in the mail because you don't have the full HTTP path to the image. Maybe there's something you can do with mail headers to make that happen. Then again, I don't know what the shelf life of the chart image would be.

Enough speculation; any SMEs out there want to weigh in?

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
firepwr,

you could always try to write the chart out to a file and then sending the file as a bit of html?!

e.g.
Code:
<!--- prepare variables we will be needing --->
<cfset sChartData = "" />
<cfset sChartName = CreateUUId() />
<!--- create chart --->
<cfchart format="jpg"
    name="sChartData"
    xaxistitle="Department"
    yaxistitle="Salary Average"
    show3D="yes">

    <cfchartseries type="bar"
        query="DataTable"
        itemcolumn="Dept_Name"
        valuecolumn="avgSal">

        <cfchartdata item="Facilities" value="35000">

    </cfchartseries>

</cfchart> 
<!--- write file to disc --->
<cffile action="write" file="#expandPath("./chartimages/#sChartName#.jpg")#" output="#sChartData#">
<!--- send mail to someone with image embedded --->
<cfmail to="someone@somewhere.com" from="me@somewhereelse.com" subject="My dynamic chart" type="html">
  <a href="[URL unfurl="true"]http://<mywebsite>/chartimages/#sChartName#.jpg"><img[/URL] src="[URL unfurl="true"]http://<mywebsite>/chartimages/#sChartName#.jpg"[/URL] border="0"> Click here to see this chart in a browser</a>
</cfmail>

Alternatively you could attach it using <cfmailparam ...>

Should there be anything else i can do for you please don't hesitate to let me know.

dl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top