Would anyone know if it is possible to format the tooltip that displays when hovering over a ColdFusion chart (when the attribute tipStyle = "MouseOver" is set)?
I would like it to be formatted as a number style to include two decimal places, even if the value is 0 (ex: 0.00 instead of just 0). I believe this value ties into the axis data format as well, so if it would be at all possible to format the axis numbers, then it might carry over to the tooltip.
I had been thinking to try and override the javascript function call for the onmouseover event that is built into the cfchart tag, but I am not sure the name of this functionor how to go about doing that either. Any thoughts/suggestions would be great. Thanks.
You could customize the annotation (ie tooltip). Just specify a custom format ie ${value;##.00} to display two decimal places.
For a list of the supported variables see the webcharts3D utility help: Designer => Design => Elements =>Parameters.
<cfsavecontent variable="style"><?xml version="1.0" encoding="UTF-8"?>
<frameChart>
<frame xDepth="12" yDepth="11"/>
<yAxis scaleMin="0" />
<elements drawShadow="true">
<morph morph="Grow"/>
<![CDATA[
X Label = $(colLabel)
X Value = ${value;##.00}
]]>
</elements>
<decoration style="FrameTopBottom" foreColor="white"/>
<paint palette="Pastel" isVertical="true" min="47" max="83"/>
<insets right="5"/>
</frameChart></cfsavecontent>
<cfchart format="png" style="#style#">
<cfchartseries type="bar">
<cfchartdata item="Apple" value="50">
<cfchartdata item="Orange" value="76.8">
<cfchartdata item="Pear" value="100.634">
</cfchartseries>
</cfchart>
Just as a note I don't think you could intercept cfchart's onmouseover event in Javascript easily because cfchart uses Flash or static images, so you'd have to do some sort of funky ActionScript <-> Javascript wizardry to intercept the event.
Related
I'm starting my next electronics project which is to create my own version of Google's Nest Thermostat. I like the whole circular dial for temperature selection and I've been having a think about how to create this myself. GUI programming is not my area of expertise (CLI all the way!).
So far I'm think along one of two lines, both involving custom widgets:
Create a widget that inherits from the pushbutton class. This subclass will contain lots of buttons, one for each step in the temperature scale, arranged in a 3/4 circle.
Create a widget that inherits from the slider class, defining an object that is curved around 3/4 of a circle. Each step is a temperature.
Now... I have no idea if these are practical solutions to this problem or if there is a much easier way of doing this. I've had a look at the style sheets and I don't THINK that is going to do it. I've had a root around Google for anything similar and not found anything yet; that said, AnalogWidgets from 3electrons at least creates dials, but these are for output rather than input.
I tried this out yesterday and it works rather nicely if you want to simulate the nest thermostat in an app this includes the js and SVG image:
https://www.svidget.io/examples/nestthermostat
HTML snippet:
<object id="nestThermostatWidget" role="svidget" data="nestThermostatWidget.svg" type="image/svg+xml" width="400" height="400">
<param name="targetTemp" value="77" />
<param name="ambientTemp" value="80" />
<param name="unit" value="F" />
<param name="state" value="cooling" />
<param name="showLeaf" value="1" />
<param name="awayMode" value="0" />
</object>
I have upgraded my cf site from cf 7 to cf 11 recently. But I am not able to set the width of cfchartseries.
I have found in Adobe documentation to set the background as "fit: Defines the width/height to fit area of background."
How can I set the width of Cfchartseries in coldfusion 11 using JSON? Please help.
Thanks.
You need to set the plotarea margin values to dynamic. This dynamically includes the scale values when determining the position of the chart. You can set the height and width of the plot area as well but this doesn't include the scales. I have found the best results is to include all styles through a JS file and calling it through the style attribute in cfchart.
Below is a basic example:
Create a JS file called test.js
{
"graphset":[
{
"border-width":1,
"background-color":"transparent",
"plotarea":{"margin":"dynamic"}
}
]
}
Add this chart code to a cfm page in the same directory as the test.js file (for example only)
<cfchart format="html" showlegend="no" height="200" width="250" title="" show3d="no" style="test.js">
<cfchartseries type="bar" paintstyle="light" color="red">
<cfchartdata item="2005" value="1000"/>
<cfchartdata item="2006" value="3000"/>
<cfchartdata item="2007" value="1000"/>
<cfchartdata item="2008" value="4000"/>
<cfchartdata item="2009" value="2000"/>
</cfchartseries>
</cfchart>
I have created a pie chart using the cfchart tag and as of the moment the labels for the chart data show outside of the pie chart, where I would like them placed inside each respective slice. I've looked through CF documentation but can seem to find a easy way to accomplish this. Can anyone shed some light on how I can just make the labels show inside each slice of the pie rather than outside?
Thank you!!!
I've tried using the following code and then using the cxml variable as the value for the style attribute on the cfchart tag. This does indeed set the labels inside the slices, but it also makes the pie chart have an odd shading to it. In addition, before applying this style I can set a value for the url parameter of the cfchart tag and cause a javascript function to fire when each slice is clicked. With the style applied, it's like it breaks each slice into separate clickable areas.
<cfsavecontent variable="cxml">
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Plain" style="Solid" is3D="false">
<dataLabels style="value" placement="Inside" foreground="white" font="Arial-12"/>
</pieChart>
</cfsavecontent>
<cfchart format="png" style="#cxml#"....>
Using the WebCharts3D application that ships with ColdFusion 8, I was able to copy the XML.
The following is what worked for me:
<cfsavecontent variable="cxml">
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Plain" style="Solid" is3D="false">
<legend spacing="0" placement="Right" font="Dialog-11">
<decoration style="None" />
</legend>
<paint palette="PastelTransluent" paint="Plain" min="44" max="95"/>
</pieChart>
</cfsavecontent>
I am counting response of a specific question and wants to display its response count through charts. I am using this code for counting response.
<cfquery name="questions">
SELECT
questions.id,
questions.question as question,
questiontypes.name as questiontype,
questiontypes.template as template,
surveys.name as surveysname
FROM
questions
LEFT JOIN answers ON questions.id = answers.fkquestionid
INNER JOIN questiontypes ON questions.fkquestiontypeid = questiontypes.id
INNER JOIN surveys ON questions.fksurveyid = surveys.id
WHERE fksurveyid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.surveyid#">
</cfquery>
<cfset response.question = questions>
<cfloop query="questions">
<cfswitch expression ="#questions.template#">
<cfcase value="truefalse">
<cfquery name="gettotaltruefalse">
SELECT COUNT( IF(result.truefalse = 1,1,NULL )) AS totaltrue,
COUNT( IF(result.truefalse = 0,0,NULL )) AS totalfalse,
COUNT( IF(result.truefalse = 1,1,NULL ))/COUNT(0)*100 AS trueperc,
COUNT( IF(result.truefalse = 0,0,NULL ))/COUNT(0)*100 AS falseperc
FROM results result
WHERE fkquestionid = <cfqueryparam cfsqltype="cf_sql_integer" value="#questions.id#">
AND NOT ISNULL(result.truefalse)
GROUP BY result.fkquestionid
</cfquery>
<cfset response.totaltruefalse = gettotaltruefalse>
</cfcase>
I am using this code to display charts.
<cfoutput query="rc.data.questions" group="id">
<cfchart format="flash" chartwidth="575" chartheight="575" show3d="yes">
<cfchartseries type="pie" paintstyle="raise" seriescolor="blue" datalabelstyle="pattern">
<cfchartdata item="true" value="#rc.data.totaltruefalse.totaltrue#">
<cfchartdata item="false" value="#rc.data.totaltruefalse.totalfalse#">
</cfchartseries>
</cfchart>
</cfoutput>
my problem is, it is showing white space instead of chart even i have tried this in all browsers.
My other answer has to do with server configuration settings based on if you have blocked access to the CFIDE directory. Another approach would be to bypass that behavior by saving the generated chart yourself (a flash file .SWF) to the web server and then displaying that file instead.
It's really easy with ColdFusion. Just add the name attribute to your <cfchart> tag. This will tell ColdFusion to store the binary chart data into the variable named with that attribute. Like this:
<cfchart format="flash" name="chartname" chartwidth="575" chartheight="575" show3d="yes">
<cfchartseries type="pie" paintstyle="raise" seriescolor="blue" datalabelstyle="pattern">
<cfchartdata item="true" value="#rc.data.totaltruefalse.totaltrue#">
<cfchartdata item="false" value="#rc.data.totaltruefalse.totalfalse#">
</cfchartseries>
</cfchart>
In that code I have named the variable chartname. Next, write the data to a file with a .SWF extension. You need to write this file to a browsable directory on your server (like an images folder or some such). Like this:
<cffile action="write" file="C:\webroot\images\mychart.swf" output="#chartname#" />
In that code I wrote the file mychart.swf to the C:\webroot\images\ folder. It can be any directory you wish as long as it is accessible under your web root. The output attribute must match the variable name given in the <cfchart> tag's name attribute and must be within #.
Next, include that SWF file in your HTML code. Like this:
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,2,0"
WIDTH="575" HEIGHT="575">
<PARAM NAME="movie" VALUE="/images/mychart.swf"/>
<PARAM NAME="quality" VALUE="high"/>
<PARAM NAME="bgcolor" VALUE="#FFFFFF"/>
<EMBED src="/images/mychart.swf"
quality="high" bgcolor="#FFFFFF" WIDTH="575" HEIGHT="575" TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>
</OBJECT>
In that code the value attribute of the <param> tag and the src attribute of the <embed> tag must match the location of the written .SWF file above (the images folder in this example).
I am guessing it has to do with setup/security on your ColdFusion server. Can you navigate to http://yourserver.com/CFIDE/GraphData.cfm (replace yourserver.com with your domain)? In order for <cfchart> to work it needs access to the CFIDE directory (NOTE - that file does not actually exist. It is merely an alias for the ColdFusion charting).
It also needs access to the CFIDE/scripts directory and the CF_RunActiveContent.js JavaScript file found there.
If you view the source of your generated page (with the blank chart) you will see something like:
<html>
<head><title>Test</title></head>
<body>
<div>
<NOSCRIPT>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,2,0"
ID="Images_5281548670100005_SWF" name="Images_5281548670100005_SWF" WIDTH="575" HEIGHT="575">
<PARAM NAME="movie" VALUE="/CFIDE/GraphData.cfm?graphCache=wc50&graphID=Images/5281548670100005.SWF"/>
<PARAM NAME="quality" VALUE="high"/>
<PARAM NAME="bgcolor" VALUE="#FFFFFF"/>
<EMBED src="/CFIDE/GraphData.cfm?graphCache=wc50&graphID=Images/5281548670100005.SWF"
quality="high" bgcolor="#FFFFFF" WIDTH="575" HEIGHT="575" TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>
</OBJECT>
</NOSCRIPT>
<script type="text/javascript" charset='utf-8' src='/CFIDE/scripts/CF_RunActiveContent.js'></script>
<script type="text/javascript" charset='utf-8'>
CF_RunContent('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \r\n codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,2,0"\r\n ID="Images_5281548670100005_SWF" name="Images_5281548670100005_SWF" WIDTH="575" HEIGHT="575">\r\n\t<PARAM NAME="movie" VALUE="/CFIDE/GraphData.cfm?graphCache=wc50&graphID=Images/5281548670100005.SWF"/>\r\n\t<PARAM NAME="quality" VALUE="high"/>\r\n\t<PARAM NAME="bgcolor" VALUE="#FFFFFF"/>\r\n<EMBED src="/CFIDE/GraphData.cfm?graphCache=wc50&graphID=Images/5281548670100005.SWF" \r\n\t\tquality="high" bgcolor="#FFFFFF" WIDTH="575" HEIGHT="575" TYPE="application/x-shockwave-flash"\r\n PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">\r\n</EMBED>\r\n</OBJECT>');
</script>
</div>
</body>
</html>
Notice the references to the CFIDE directory. If that directory is not accessible the <cfchart> tag will not work correctly (you will get a blank chart).
Two relevant discussions about this with potential work arounds:
On the Adobe forums
By Brandon Purcell
I am using the WebCharts3D interface to create and modify charts, and then using the generated XML style as an in-line style in my Coldfusion code.
So this shows up correctly in the WebCharts3D:
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Double" style="Solid">
<title font="Arial-18-bold">
<decoration style="None"/>This is a title
</title>
</pieChart>
This simply shows the example title with no box around it, and set to the desired font size and weight. You can take this code, copy it into the WebCharts "XML Style" window, apply it, and see that it works.
I use this in my Coldfusion code like this:
<cfsavecontent variable="piecontent">
<?xml version="1.0" encoding="UTF-8"?>
<pieChart depth="Double" style="Solid">
<title font="Arial-18-bold">
<decoration style="None"/>This is a title
</title>
</pieChart>
</cfsavecontent>
<cfchart name="mychart" format="png"
style="#piecontent#">
<cfchartseries type= "pie">
<cfchartdata item="sample1" value="10">
<cfchartdata item="sample2" value="20">
</cfchartseries>
</cfchart>
The title correctly has "decoration" set to "none", because there is no box around it, but the title font size and weight is totally ignored. Is this a bug? Is there a workaround?
EDIT: It appears that this problem of ignored font size and weight is ALSO true for the overall font, like if you put this: <pieChart depth="Double" style="Solid" font="Arial-16-Bold">.
It seems like those particular settings are ignored in favor of the cfchart tag's font attributes. Try using those instead:
<cfchart format="png" font="Arial" fontBold="true" fontSize="18">
EDIT: While the above works with pie charts (only), it seems like another bug... What does work is interfacing with webcharts directly. It is more involved, but offers complete control over chart settings.
My experience, though I can't find any proof online other than my own testing, is that ColdFusion's implementation of Webcharts does not support styling the title.