Working with Dates

One thing that’s worth giving special mention to in this chapter is the way in which cfchart handles date values when they’re on the y-axis. If you remember from Example 17-1, you can use labelformat="Date" to tell cfchart to format the values along the value axis as dates. If you try the following code, however, you’ll probably notice something strange:

<cfchart format="Flash" labelformat="Date">
  <cfchartseries type="Scatter" serieslabel="New Years Eve Party Hosts">
    <cfchartdata item="Zack" value="12/31/1972">
    <cfchartdata item="Becky" value="12/31/1996">
    <cfchartdata item="Joe" value="12/31/1984">
    <cfchartdata item="Lynda" value="12/31/2002">    

If you look at the dates on the vertical axis, you should notice that they are all 12/31/69. Additionally, if you move your mouse over any of the data points, they are also all 12/31/69. The issue here is that cfchart does not accept formatted dates (such as mm/dd/yyyy) as data-point values. If you have dates you want to plot on the y-axis of a chart, you’ll have to reformat them for cfchart. cfchart expects dates passed as values be formatted in epoch seconds, adjusted for your UTC (Coordinated Universal Time) offset. What’s more, the resulting number must be multiplied by 1000 (presumably to account for milliseconds?). So, how do you do all of this? The simple solution is to create a user-defined function to handle the conversion for you. This allows you to call the function repeatedly, without ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.