0

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.

Tan
  • 1,433
  • 5
  • 27
  • 47
  • 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 [``](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7930.html) first, specifically the url attribute. – Leigh Jul 17 '13 at 20:09
  • @Leigh I have attached the images and updated my post. Please take a look at it. – Tan Jul 17 '13 at 21:30
  • As you can see, the dates in second image stopped displaying after 2013-07-10 – Tan Jul 17 '13 at 21:33
  • 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 Jul 17 '13 at 22:31
  • @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 Jul 17 '13 at 22:36
  • QoQ is faster and that's why I'm using it. I hope this answers your question? – Tan Jul 17 '13 at 22:36

2 Answers2

0

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.)

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • I have tried running the query only for FIRSTCONN while commenting out all other Qoq (for SECONDCONN,THIRDCONN) etc) for a long date range and it works fine. However, when I try to mention SECONDCONN and more , the label starts disappearing. It doesn't matter whether my date range is long or short. Also, since I'm using Coldfusion 8 , is the link you have just mentioned, which is for Coldfusion 9, going to work for me? – Tan Jul 18 '13 at 15:07
  • Also, how come the x-axis is automatically plotting dates, although I haven't explicitly mentioned anything in my code? – Tan Jul 18 '13 at 15:25
  • Well how are you defining a "short date range"? How many records? It works fine with CF9. (I will test under CF8 later.) Can you try the updated example above? Regarding the link, the charting tool in the link has been around since MX7. The only difference is it has more features in later versions. – Leigh Jul 18 '13 at 15:37
  • Hey, The Test code is working fine for two line charts.Both the line charts are displayed till the end. – Tan Jul 18 '13 at 18:53
  • Yeah, like I said it is probably the *amount* of data you are trying chart that is the problem. Most likely the engine cannot fit all the labels on the x-axis. You need to play around with the [chart styles](http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_c_05.html). – Leigh Jul 18 '13 at 19:06
  • 1)But why it is working fine with the case when I'm only displaying a single line chart. The amount of data remains same I believe for one line chart or multiple line chart 2) Can't I customize my query just like you did?Probably I'm wondering how would I display large number of dates in the listtoArray()? – Tan Jul 18 '13 at 19:20
  • The manual query has nothing to do with it. With your single line chart, are less dates to chart. For the sake of argument, say the first query contains 20 dates (or 20 data points). Then the second query contains 30 more data points, for a grand total of 50. There is enough room to display the first 20 dates/labels, but not all 50. Make sense? – Leigh Jul 18 '13 at 19:43
  • I see. Yes, that makes sense. Thank you. I'm playing with chart styles and trying to figuring out the reason. – Tan Jul 18 '13 at 20:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33786/discussion-between-tan-and-leigh) – Tan Jul 19 '13 at 16:38
0

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.

Tan
  • 1,433
  • 5
  • 27
  • 47