• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

17. Graphing and Charting > 17.2. Working with Dates

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 the need for cutting and pasting the conversion formula each time you need to perform the calculation. Example 17-2 shows the code for a user-defined function called cfchartDateFormat( ) that handles the date conversion required by cfchart, as well as a cfchart example that makes use of the function.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint