4
votes

I am trying to create a simple line chart in ColdFusion 11 and would like to format the xAxis to show a date format like mm-dd-yy instead of the full date/timestamp that is showing by default.

My code is:

      <cfchart format="html"
               chartwidth="800"
               chartheight="400"
               xaxistitle="Date"
               yaxistitle="Amount"
               showlegend="yes"
               fontsize="12"
               font="Arial"
               showMarkers="no"
               xAxis=#[{"format"="Date","label":"Date"}]#>

        <cfchartseries type="line"
                      query="getAmounts"
                      valueColumn="amount"
                      itemColumn="date">

      </cfchart>

The xAxis attribute is giving this error:

You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.

I have tried several different variations of the xAxis attribute with no luck - the documentation is unclear as to what format this should be in. Any help would be appreciated.

1
The square brackets and the reference to an array in the error message might be a meaningful combination.Dan Bracuk
I have tried it with and without the brackets.JamesE
Did you try it without the octothorps?Dan Bracuk

1 Answers

1
votes

The format needs to be something like this...

<cfset myStruct = {"item"={"font-angle"=-90}}/>

And then just set xAxis = "#myStruct#" - you can do that all in the cfchart tag but it is just a little easier to read when the struct gets big. That is the correct format as that is working for us to set the angle of each item. But, I don't know what all of the options are for keys in xAxis. The docs just say "A struct of keys used to style x axis such as format, guide, item, and label."

With that being said, couldn't you just set the correct format to the field "date" in the "getAmounts" query? Then you wouldn't have to deal with it when you output it to the chart.