Re: using advanced query builder for a chart
Whew! I figured out a really awesome solution, which has a ton of uses.
First of all, as I should have realized, ANY variable in a coldfusion tag is
going to be figured out when the report is called, NOT for every query result.
In other words, query.xxx or report.xxx or whatever is NEVER going to work
correctly inside of a tag, not even in a report function or the Advanced Query
builder.
However, there is a straightforward way around this. Simply make a report
function with arguments, and in your field's expression editor call the
function and pass in the query or report variables:
#report.yourFunction(query.field1, query.field2)#
You can do all sorts of Coldfusion function magic and return whatever form of
result you want.
For my particular example (dynamically creating a query object for a chart to
be inserted), I had to add a not-so-obvious step: creating my query object with
a shared scope (in this case, the Request scope), otherwise the variable is
trapped in the function's scope. So this was my solution: I had a chart with
the "Print When" option calling my function "getChartQuery" (passing in the
query variables, of course). The function builds "Request.ThisChartQuery" and
returns True if there's something in it (the "Print When" logic uses the
boolean to decide whether to show the chart or not). Then my chart is still
query-based, but the Advanced Query builder has NOTHING in it at all, except
for the variable containing the query object ("Request.ThisChartQuery").
There was another solution I found where the report function makes the entire
chart (using cfchart tags, etc) and saves it as a PNG file, and then returns
the path to the image. Then you simply add an image field to the report, and
you use the expression builder to call the function. Well, hope this helped
someone!
|