2

I am trying to build a scatter plot with ColdFusion 9. The input for the x axis is numeric and not evenly spaced. Here's what I tried:

<cfquery name="qryData" datasource="#datasource#">
    SELECT x, y
    FROM data
</cfquery>

<cfchart format="png" xaxistype="scale">
    <cfchartseries type="scatter" query="qryData" itemcolumn="x" valuecolumn="y">
</cfchart>

This generates a graph with the x values in the same order as they are in the query, rather than in numerical order:

enter image description here

What do I need to change to get a real scatter plot with the x axis in numerical order and correctly spaced between values?

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Can you `ORDER BY` in the query? – Shawn May 13 '19 at 19:55
  • @Shawn Yes, I could do that. However, the points will still be evenly spaced along the x axis, which isn't correct. The documentation tells me that `xaxistype="scale"` is supposed to do what I want, but it isn't. – Code-Apprentice May 13 '19 at 19:57
  • Are you able to provide some sample data? – Shawn May 13 '19 at 20:10
  • 1
    What do your x and y axes represent? In addition to the sample data, what is the datatype of your `x` and `y` columns? I'm not able to duplicate your results, although I don't currently have access to CF9. Minimum of CF10. ( < OT>Which would remind me to point out that CF9 is _way_ out of date, and should probably be upgraded< /OT>) – Shawn May 13 '19 at 20:29
  • @Shawn The table is in a MS SQL database and the x and y columns are both defined as `real`. (Note: I have complete control over the table definition, so I can change that if necessary.) I definitely wish I could upgrade the entire system. However, there are business considerations that are out of my hands here. – Code-Apprentice May 13 '19 at 20:48
  • One possible clue to this behavior: when I set `sortxaxis=true`, the values are sorted as strings, not numbers, so for example `1872.3` comes before `544.8`. CF appears to see the `x` and `y` columns as strings instead of numeric. Perhaps the issue is actually with the query and/or column datatypes and conversion from db types to CF types. – Code-Apprentice May 13 '19 at 20:54
  • Are `x` and `y` already calculated in your table, or is there some calculation happening in your actual query? – Shawn May 13 '19 at 21:21
  • Also, I thought `cfchart` was very buggy back in CF9. And there's this: https://github.com/cfjedimaster/ColdFusion-UI-the-Right-Way/blob/master/chapters/cfchart/index.md – Shawn May 13 '19 at 21:25
  • @Shawn `x` and `y` are as shown above. They are queried directly from the table. No calculations in either the SQL or in ColdFusion. – Code-Apprentice May 13 '19 at 21:39
  • @Shawn This appears to be a bug in CF: https://www.raymondcamden.com/2009/08/19/Problem-with-Scatter-graphs-in-ColdFusion – Code-Apprentice May 13 '19 at 23:27
  • The link I posted above is actually Ray's CF UI the Right Way post about `cfchart`. I wonder if this was one of the reasons he started working on that. :-) Regardless, that link for CFUI the Right Way has a lot of good info about how to do some of the things that CF tried to "make easier". – Shawn May 14 '19 at 00:01
  • @Shawn Thanks a lot for your help. After struggling with this for most of the day, I've decided to find another solution for doing this, probably a JavaScript library that I can embed easily in a CFM template. – Code-Apprentice May 14 '19 at 00:07

0 Answers0