Advertisement
sqlninja1

Untitled

Feb 11th, 2015
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3.     <head>
  4.         <title>Bar Chart</title>
  5.         <script src="../Chart.js"></script>
  6.         <meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
  7.         <style>
  8.             canvas{
  9.             }
  10.         </style>
  11.  
  12.          <cfquery name="event_details" dataSource="db9">
  13.                     SELECT nCompetitor as competitor_name, nEvent as event_name, nClass as class_name, nScore as score, nDate as competition_date, nSingle, nTriple, nDouble, nKey
  14.                     FROM nDataAll
  15.                     WHERE nCompetitorID = <cfqueryparam cfsqltype="cf_sql_integer" value="1" />
  16.                     ORDER BY nDate DESC
  17.                 </cfquery>
  18.  
  19.                 <!--- Convert the entire query to an array  Function--->
  20. <cffunction name="queryToArray" access="private" returntype="array" output="false">
  21.         <cfargument name="q" type="query" required="yes" />
  22.         <cfargument name="cb" type="any" required="no" />
  23.         <cfscript>
  24.             var local = {};
  25.             if (structKeyExists(server, "railo")) {
  26.                 local.Columns = listToArray(arguments.q.getColumnList(false));
  27.             }
  28.             else {
  29.                 local.Columns = arguments.q.getMetaData().getColumnLabels();
  30.             }
  31.             local.QueryArray = ArrayNew(1);
  32.             for (local.RowIndex = 1; local.RowIndex <= arguments.q.RecordCount; local.RowIndex++){
  33.                 local.Row = {};
  34.                 local.numCols = ArrayLen( local.Columns );
  35.                 for (local.ColumnIndex = 1; local.ColumnIndex <= local.numCols; local.ColumnIndex++){
  36.                     local.ColumnName = local.Columns[ local.ColumnIndex ];
  37.                     if( local.ColumnName NEQ "" ) {
  38.                         local.Row[ local.ColumnName ] = arguments.q[ local.ColumnName ][ local.RowIndex ];
  39.                     }
  40.                 }
  41.                 if ( structKeyExists( arguments, "cb" ) ) {
  42.                     local.Row = cb( local.Row );
  43.                 }
  44.                 ArrayAppend( local.QueryArray, local.Row );
  45.             }
  46.             return( local.QueryArray );
  47.         </cfscript>
  48.     </cffunction>
  49.  
  50.     </head>
  51.  
  52.     <body>
  53.         <canvas id="canvas" height="450" width="600"></canvas>
  54.  
  55. <!--- Convert the entire query to an array of structures --->
  56. <cfset arrEventdetArray = queryToArray( event_details ) />
  57. <!---Show Array --->
  58. <cfdump var="#arrEventdetArray#">
  59.  
  60.  <cfset arrEventDetails = serializeJSON( queryToArray( event_details ) ) />
  61. <cfdump var="#arrEventdetails#">
  62.  
  63.  
  64. <cfset myList = ValueList(event_details.event_name,',')>
  65. <!--Dumping valulist to see what it looks like-->
  66. <cfdump var="#myList#">
  67.     <script>
  68.  
  69.         var barChartData1 = {
  70.     labels: [<cfoutput>"#myList#"</cfoutput>]
  71.     ,
  72.     datasets: [
  73.         {
  74.             label: "My First dataset",
  75.             fillColor: "rgba(220,220,220,0.2)",
  76.             strokeColor: "rgba(220,220,220,1)",
  77.             pointColor: "rgba(220,220,220,1)",
  78.             pointStrokeColor: "#fff",
  79.             pointHighlightFill: "#fff",
  80.             pointHighlightStroke: "rgba(220,220,220,1)",
  81.             data: [65, 59, 90, 81, 56, 55, 40]
  82.         },
  83.         {
  84.             label: "My Second dataset",
  85.             fillColor: "rgba(151,187,205,0.2)",
  86.             strokeColor: "rgba(151,187,205,1)",
  87.             pointColor: "rgba(151,187,205,1)",
  88.             pointStrokeColor: "#fff",
  89.             pointHighlightFill: "#fff",
  90.             pointHighlightStroke: "rgba(151,187,205,1)",
  91.             data: [28, 48, 40, 19, 96, 27, 100]
  92.         }
  93.     ]
  94. };
  95.  
  96.  
  97.  
  98.     var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(barChartData1);
  99.    
  100.     </script>
  101.  
  102. <!--- Salted hell you could valuelist it. valuelist(myQuery.labelColumn), valuelist(myQuery.datacolumn), then just spit them out in the js. labels : [<cfoutput>#labellist#</cfoutput], etc.  --->
  103.  
  104. <!---My attempt to loop and make and avoid JSON --->
  105.    
  106.     </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement