EasyCFM.COM ColdFusion Forums / General Discussion / colouring individual data items

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: colouring individual data items

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

Lossed
12-11-2006 @ 9:53 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

I have this pretty, oh so pretty bar chart of users' resting heart rates over the preceeding two weeks. I'd like to colour any bar that exceeds users rhr average  by more than, say, 10%, a different colour so it really stands out and looks even prettier Wink
However, it seems like I can only colour a data series, not individual data items.
And, I'm trying to keep the dates in descending order, left to right.
So, can anyone think of any nifty ways to do this?
Maybe a whole heap of data series'?
I shall keep playing on this chart tomorrow and hopefully something springs to mind while sleeping on it tonight Smile


Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

SirRawlins
12-12-2006 @ 12:06 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 951
Joined: Mar 2006

Hey buddy,

I've done stacks of work with <cfchart> so shouldnt have too many issues figuring this out.

It would be a great help if i could see the code you have at the moment, a copy of your database structure so i know what data we have to work with.

If you can post those puppies back i'll give you a hand.

Rob

Lossed
12-12-2006 @ 4:17 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

Thanks Rob,

On the page that updates / inserts the user's rhr I have the code below.
Essentialy, after verifying the rhr and user, the myrhr table is updated/inserted into and the users myrhr query is run again and copied back into the session scope. all the subsequent queries are run off that session.sin.qmyrhr query.
The charts are to show the users rhr over the last 14 days (13 including current focus date).
For now, I have included a differently coloured dataseries to show the users avg rhr. Ideally I'd like to highlight every rhr that was, say, over 10% of the average, but I'm unsure how to do that, so the avg rhr data series is my compromise.

-------------------

<!---update session.sin.qmyrhr--->
<cfquery name="qmyrhr" datasource="blah" username="blah" password="blah">
     select r.id,r.uid,r.rdate,r.rhr,
          month(r.rdate) as mfocus,year(r.rdate) as yfocus,day(r.rdate) as dfocus,
          sum(rhr) as totalrhr,
          convert(date_format(r.rdate,'%Y-%m-%d') using utf8) as frdate,
          if(datediff(now(),r.rdate) < 14,1,0) as last14days
     from myrhr r
     where r.uid=<cfqueryparam value="#session.sin.id#" cfsqltype="cf_sql_integer">

     group by r.rdate desc with rollup</cfquery>
<cflock scope="session" type="exclusive" timeout="30">
     <cfif variables.qmyrhr.recordcount>
          <cfset session.sin.qmyrhr=duplicate(variables.qmyrhr)>
     <cfelse>
          <cfset temp=structdelete(session.sin,'qmyrhr')>
     </cfif>
</cflock>
<!---avg overall rhr of user--->
<cfset myrhravg=int(session.sin.qmyrhr.totalrhr[session.sin.qmyrhr.recordcount] / (session.sin.qmyrhr.recordcount-1))>
<!---re/write L14 charts for every date from form.rdate + 13--->
<!---get all affected dates forward of/on the form.rdate--->
<cfquery name="ql14dates" dbtype="query">
          select frdate
          from session.sin.qmyrhr
          where rdate < <cfqueryparam value="#dateadd('d',14,form.rdate)#" cfsqltype="cf_sql_date">
               and rdate >= <cfqueryparam value="#form.rdate#" cfsqltype="cf_sql_date"></cfquery>
<!---get data & build new charts for each affected date--->
<cfloop query="variables.ql14dates">
     <cfquery name="ql14" dbtype="query">
          select rhr,dfocus
          from session.sin.qmyrhr
          where rdate <=<cfqueryparam value="#variables.ql14dates.frdate[variables.ql14dates.currentrow]#" cfsqltype="cf_sql_date">
               and rdate > <cfqueryparam value="#dateadd('d',-13,variables.ql14dates.frdate[variables.ql14dates.currentrow])#" cfsqltype="cf_sql_date"></cfquery>
     <cfif variables.ql14.recordcount>
          <!---get lowest rhrh for the cfchart scalefrom--->
          <cfquery name="qlowest" dbtype="query">
               select rhr from variables.ql14 order by rhr asc</cfquery>
          <!---build chart--->
          <cfchart
               format="png"
               backgroundcolor="##000000"
               foregroundcolor="##CCCCCC"
               databackgroundcolor="##000000"
               labelformat="number"
               chartheight="200"
               chartwidth="154"
               scalefrom="#variables.qlowest.rhr[1]#"
               show3d="yes"
               name="l14">

               <!---red bars of each rhr value available in last 14 days--->
               <cfchartseries
                    type="bar"
                    query="variables.ql14"
                    valuecolumn="rhr"
                    itemcolumn="dfocus"
                    paintstyle="plain"
                    serieslabel="rhr"
                    seriescolor="##ff0000">

                    <cfloop query="variables.ql14">
                         <cfchartdata
                              item="#variables.ql14.dfocus[variables.ql14.currentrow]#"
                              value="#variables.ql14.rhr[variables.ql14.currentrow]#">

                    </cfloop>
               </cfchartseries>
               <!---green bg bars of users avg rhr. Looks a bit like a green wall in the bg--->
               <cfchartseries
                    type="bar"
                    paintstyle="plain"
                    serieslabel="avg: #variables.myrhravg#"
                    seriescolor="##00ff00">

                    <cfloop from="1" to="#variables.ql14.recordcount#" index="z">
                         <cfchartdata
                              item="#variables.ql14.dfocus[variables.z]#"
                              value="#variables.myrhravg#">

                    </cfloop>
               </cfchartseries>
          </cfchart>
          <!---write the png to file for reference later rather than to cache--->
          <cffile
               action="write"
               charset="ISO-8859-1"
               nameconflict="overwrite"
               file="#application.fr#pic\crew\mydiary\rhr\l14\#session.sin.id#_#variables.ql14dates.frdate[variables.ql14dates.currentrow]#.png"
               output="#variables.l14#">

          <cfset temp=structdelete(variables,'l14')>
     </cfif>
</cfloop>


Tks,
Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

This message was edited by Lossed on 12-12-06 @ 4:26 PM


Website Designed and Developed by Pablo Varando.