Custom Y-Axis Labels in ColdFusion Charting

This post is more than 2 years old.

This question came in via a reader and led to some interesting aspects of the ZingChart engine embedded in ColdFusion 10 (remember though that this is Enterprise only). The reader wanted to replace the numeric labels on the Y-Axis with strings instead. From my experience with ZingChart in the past, I assumed this was probably possible. The engine is incredibly powerful and has about a bazillion options. I reached out to the company on Twitter and with their help, I was able to get it working.

First, let's start with a simple bar chart.

//sample data
data = queryNew("name,age", "cf_sql_varchar,cf_sql_integer", [



<cfchart format="html" showLegend="false" >

	<cfchartseries type="bar" query="data" valueColumn="age" itemColumn="name" >


I've got a fake query (and fake data, Scott really isn't that old) that I pass to cfchart. Here is the result.

The goal now is to change the y-axis values so that I can label a few values from young, to medium, and to old. There are two things you need to do in order to make this work. First, you need to specify your y-axis values instead of letting this happen automatically. For a chart involving age, this is rather easy. Depending on your data this may or may not be a big deal. This can be done via the yaxisvalues attribute of cfchart: yaxisvalues="#[10,20,30,40,50,60,70]#".

That helps define the actual range on the yaxis. To define the labels, you will use the yaxis attribute. This takes a structure of options. I believe the documentation for what you can send is defined here, but I'm not entirely sure about that. With the ZingChart folks helping me out on Twitter, I was told specifically what to pass - a labels key. Let's look at an updated example.

<cfchart yaxisvalues="#[10,20,30,40,50,60,70]#" yaxis="#{"labels":["","","young","medium","old","",""]}#" format="html" showLegend="false" >

	<cfchartseries type="bar" query="data" valueColumn="age" itemColumn="name" >


Notice how some of the labels are blank. This creates the effect of a chart with only the string labels, not the numbers.

If you want to keep the numbers as well as the strings, simply include them in the labels.

<cfchart yaxisvalues="#[10,20,30,40,50,60,70]#" yaxis="#{"labels":["10","20","young","medium","old","60","70"]}#" format="html" showLegend="false" >

	<cfchartseries type="bar" query="data" valueColumn="age" itemColumn="name" >


All in all, pretty nice. You can do other things with the labels including rotating them, sizing them, etc. As I said, ZingChart has a huge amount of options. For those of you not using ColdFusion 10 Enterprise, it may be worth purchasing as is and just using it natively. The price is $250 for a single domain and while there are many free options out there, I've been very impressed with ZingChart and their technical support. (As I mentioned above, they helped me out on Twitter and this is not the first time they have done so.)

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by pat branley posted on 10/18/2013 at 12:22 AM

I recommend everyone to buy the licence. You are not entitled to upgrades of zingcharts with cf ent. The version shipped is old and has some bugs - esp related to rotating axis

Comment 2 by Alex Colt posted on 5/23/2015 at 6:27 AM

Yes I totally agree with you