0
votes

I'm running the following query and after running the QoQ for SECONDCONN , I am not getting the desired output in my cfchart.

<!--- QoQ for FIRSTCONN --->
<!--- Master Query --->
<cfquery datasource = "XX.XX.X.XX" name="master1">
     SELECT STR_TO_DATE(date_format(Timedetail,'%m-%d-%Y'),'%m-%d-%Y') as FIRSTCONN
            , COUNT(Timedetail) as FIRSTOccurances
            , EVENTS 
     FROM  MyDatabase
     WHERE EVENTS = "FIRST" 
     GROUP BY FIRSTCONN ;
</cfquery> 

<!--- Detail Query --->
<!--- <cfdump var = "#master#"> --->
<cfquery dbtype="query" name="detail1">
    SELECT  *
    FROM master1 
    WHERE FIRSTCONN  >= <cfqueryparam value="#form.startdate#" cfsqltype="cf_sql_varchar"> 
    AND   FIRSTCONN  <  <cfqueryparam value="#dateAdd('d', 1,form.enddate)#" cfsqltype="cf_sql_varchar">;
</cfquery>  


<!--- QoQ for SECONDCONN --->
<!--- Master Query --->
<cfquery datasource = "XX.XX.X.XX" name="master2">
    SELECT STR_TO_DATE(date_format(Timedetail,'%m-%d-%Y'),'%m-%d-%Y') as SECONDCONN
           , COUNT(Timedetail) as SECONDOccurances
           , EVENTS 
    FROM  MyDatabase
    WHERE EVENTS = "SECOND" 
    GROUP BY SECONDCONN ;
</cfquery> 

<!--- Detail Query --->
<!--- <cfdump var = "#master#"> --->
<cfquery dbtype="query" name="detail2">
    SELECT  *
    FROM   master2 
    WHERE  SECONDCONN  >= <cfqueryparam value="#form.startdate#" cfsqltype="cf_sql_varchar"> 
    AND    SECONDCONN  <  <cfqueryparam value="#dateAdd('d', 1,form.enddate)#" cfsqltype="cf_sql_varchar">;
</cfquery>  


<cfchart format="flash"  chartwidth="1000" chartheight="500" scalefrom="0" scaleto="50000" xAxisTitle="Dates" yaxistitle="Number of Connections">
     <cfchartseries  query="detail1" type="line" itemColumn="FIRSTCONN" valueColumn="FIRSTOccurances" > 
     <cfchartseries  query="detail2" type="line" itemColumn="SECONDCONN" valueColumn="SECONDOccurances" > 
     </cfchartseries>
</cfchart>

On X Axis, the chart is displaying the correct startdate but it stops displaying the dates after middle point somewhere and rest of the line chart is displayed without any dates mentioned on the x-axis. What could be the reason? The dates are displaying properly when I ran just one query, that is QoQ for FIRSTCONN.

Image #1 attached shows the output with only one query , that is QoQ for FIRSTCONN

Image #2 is for the both and showing undesirable output.

Another point I noticed is that when I run the query for only SECONDCONN, I see an output without any dates mentioned on the x-axis. What could be th reason? I have attached image #3 below for the reference.there is no change in the query.

The cfchart code I'm using is as follows:

<cfchart format="flash"  
          chartwidth="1000" 
          chartheight="500" 
          scalefrom="0" 
          scaleto="50000" 
          xAxisTitle="Date" 
          yaxistitle="Number of Connections" 
          showLegend = "yes" 
          showMarkers = "yes"
          sortXAxis= "yes"
          tipStyle="MouseDown"
          >



         <cfchartseries  query="detail2" type="line" itemColumn="SECONDCONN " valueColumn="SECONDOccurances" > 

  </cfchartseries>  
</cfchart>  

The cfdump of second query is as follows:

query
RESULTSET   
query
    SECONDCONN                SECONDOCCURANCES   EVENTS
1   {ts '2013-06-24 00:00:00'}  556             SECOND
2   {ts '2013-06-25 00:00:00'}  2710            SECOND
3   {ts '2013-06-26 00:00:00'}  2854            SECOND
4   {ts '2013-06-27 00:00:00'}  6348            SECOND
5   {ts '2013-06-28 00:00:00'}  4285            SECOND
6   {ts '2013-06-29 00:00:00'}  2843            SECOND
7   {ts '2013-06-30 00:00:00'}  875             SECOND
8   {ts '2013-07-01 00:00:00'}  4033            SECOND
9   {ts '2013-07-02 00:00:00'}  3211            SECOND
10  {ts '2013-07-03 00:00:00'}  2882            SECOND
11  {ts '2013-07-04 00:00:00'}  978             SECOND
12  {ts '2013-07-05 00:00:00'}  1727            SECOND
13  {ts '2013-07-06 00:00:00'}  811             SECOND
14  {ts '2013-07-07 00:00:00'}  522             SECOND
15  {ts '2013-07-08 00:00:00'}  2556            SECOND
16  {ts '2013-07-09 00:00:00'}  1160            SECOND
17  {ts '2013-07-10 00:00:00'}  8580            SECOND
18  {ts '2013-07-11 00:00:00'}  2630            SECOND
19  {ts '2013-07-16 00:00:00'}  12              SECOND 

Please let me know if I can answer more questions.

2
We need to see a dump of the query used for the chart to help with #1. Posting a screen shot would not hurt either. Question #2 should be posted separately. Hint: Read the documentation on <cfchart> first, specifically the url attribute.Leigh
@Leigh I have attached the images and updated my post. Please take a look at it.Tan
As you can see, the dates in second image stopped displaying after 2013-07-10Tan
That cannot be the real code, as there is no definition for a query named "detail". Not to mention, you charting the "detail" query twice... Can you post the actual code that generated the chart in the screen shot? Also, is there a reason you are using a QoQ instead filtering within the database query.Leigh
@Leigh I apologize for the confusion. I have updated the code. I'm using detail1 and detail 2 now. The code posted is the actual code now.Tan

2 Answers

0
votes

Without seeing a dump of the query data, my guess is the charting engine may have decided there are too many values to reasonably display on the x-axis. (I tested your code and it works fine with CF9). Try it with a smaller date range and see if the date labels reappear. If so, you may need to customize the chart settings to get a better fit. Here are some of the pertinent style settings.

  • isHideOverlapped - hide/show labels that overlap
  • skipLabels - adjust to display every n labels instead of all
  • orientation - label orientation (horizontal or vertical)

Test Code

<cfset detail1 = queryNew("")>
<cfset queryAddColumn(detail1, "FIRSTCONN", "date", listToArray("2013-07-31,2013-08-15,2013-08-17"))>
<cfset queryAddColumn(detail1, "FIRSTOccurances", listToArray("3,5,6"))>

<cfset detail2 = queryNew("")>
<cfset queryAddColumn(detail2, "SECONDCONN", "date", listToArray("2013-08-10,2013-08-18,2013-08-20"))>
<cfset queryAddColumn(detail2, "SECONDOccurances", listToArray("4,10,8"))>
<cfchart format="flash"  xAxisTitle="Dates" yaxistitle="Number of Connections">
       <cfchartseries  query="detail1" type="line" itemColumn="FIRSTCONN" valueColumn="FIRSTOccurances" /> 
       <cfchartseries  query="detail2" type="line" itemColumn="SECONDCONN" valueColumn="SECONDOccurances" /> 
</cfchart>

QoQ is faster and that's why I'm using it.

Honestly, that is not a good approach for handling a slow running queries. The best place to optimize a db query is in the database. Take the time to examine the query plan and find the bottleneck, add the appropriate indexes, etcetera. By using QoQ's you incur a lot of extra network o/h by pulling back a lot of extra data that is ultimately discarded. Not to mention, the memory required to build a new resultset. It is a lot of wasted resources and will not scale well.

(That said, I believe you have already opened a separate thread regarding the query speed. So rather than mixing questions again, I will leave that conversation for your other thread.)

0
votes

The problem was resolved when I changed the order of displaying line chart. I mean I was displaying in increasing order fashion in the following manner:

<cfchartseries  query="detail1" type="line" itemColumn="FIRSTCONN" valueColumn="FIRSTOccurances" > 
<cfchartseries  query="detail2" type="line" itemColumn="SECONDCONN" valueColumn="SECONDOccurances" > and so on till seventh connection.

When I started displaying it in decreasing like the following :

<cfchartseries  query="detail7" type="line" itemColumn="SEVENTHCONN" valueColumn="SEVENTHOccurances" > 
    <cfchartseries  query="detail6" type="line" itemColumn="SIXTHCONN" valueColumn="SIXTHOccurances" > and so on till FIRST CONNECTION

The problem was resolved but I'm not sure what was the reason behind it.