Solved

Cfgraph, Coldfusion and MySQL getting started

Posted on 2007-11-14
3
553 Views
Last Modified: 2008-02-01
Hi,

I need to display the hits, and visits of our site in a bar chart using Coldfusion. An example of the SQL data is like so....

daily_id, date, hits, visits
1, 11/13/2007, 20000, 400000
2. 11/12/2007, 20000, 400000

but I would like to have a drop down menu for months and show a bar chart of the daily hits throughout the month. This is what I've got started...

<cfquery name="get_general_stats" datasource="#dsn#">
        SELECT *, COUNT(visits) as "visits"
        FROM stats_daily
        ????
         WHERE month of the date =  '#form.date#'
</cfquery>


<CFCHART
             backgroundcolor="F2ECEC"
               CHARTWIDTH="950"
               CHARTHEIGHT="180"
         ROTATED="no"
               showlegend="yes"
              showmarkers="yes"
             SHOW3D="yes"
         XOFFSET=".01"
         YOFFSET=".02"
               FONTSIZE="10"
         FONTBOLD="Yes"
               DATABACKGROUNDCOLOR="DDDDDD"
             SCALETO="100"
         GRIDLINES="5"
         SHOWXGRIDLINES="no"
         SHOWYGRIDLINES="yes">
            
            <CFCHARTSERIES
           TYPE="bar"
         QUERY="query_name"
           ITEMCOLUMN="date"
           VALUECOLUMN="visits"
           SERIESLABEL="Visits"
           SERIESCOLOR="F94A4A">
             
            </cfchart>

Thanks,

B
0
Comment
Question by:brihol44
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
bayesianmind earned 500 total points
ID: 20284750
Have you tried this? Count(field) counts the number of records that match a query, which is probably not what you wanted.

<cfquery name="get_general_stats" datasource="#dsn#">
        SELECT *
        FROM stats_daily
        ????
         WHERE month of the date =  '#form.date#'
</cfquery>

That should populate the required fields and get you going.
0
 

Author Comment

by:brihol44
ID: 20291270
Nice! Thank you, I got it! However how would I loop over all the daily values in bar chart? So if I selected the month of October 2007 I would get all 31 days for the month with a bar value representing each day.

I get the value and the bar chart with the correct value with adding the two variables below. I just need some hints to figure out out to display all the days for each month/year selected.



<cfset month = "11">
	<cfset day = "08">
 
	<cfquery name="get_visits" datasource="#dsn#">
	  SELECT *
	  FROM stats_daily
	  WHERE EXTRACT(MONTH FROM date) = '#month#' AND
	  EXTRACT(DAY FROM date) = '#day#' 
	</cfquery>
 
    <CFCHART
		 backgroundcolor="F2ECEC"
  		 CHARTWIDTH="950"
  		 CHARTHEIGHT="180"
         ROTATED="no"
  		 showlegend="yes"
 		 showmarkers="yes"
		 SHOW3D="yes"
         XOFFSET=".01"
         YOFFSET=".02"
  		 FONTSIZE="10"
         FONTBOLD="Yes"
  		 DATABACKGROUNDCOLOR="DDDDDD"
		 SCALETO="100"
         GRIDLINES="5"
         SHOWXGRIDLINES="no"
         SHOWYGRIDLINES="yes"> 
		
		<CFCHARTSERIES 
    	 TYPE="bar" 
         QUERY="get_visits"
    	 ITEMCOLUMN="Visits"
    	 VALUECOLUMN="visits"
    	 SERIESLABEL="Visits"
    	 SERIESCOLOR="F94A4A">
		 
		</cfchart>

Open in new window

0
 
LVL 3

Expert Comment

by:bayesianmind
ID: 20292005
Isn't that what the first code you posted does? Or are you looking to have multiple months selectable and displayed?
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question