Advertisement
sqlninja1

Serializing Query data for chartjs/highcharts

Feb 11th, 2015
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="../Chart.js"></script>
  2.         <meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
  3.         <style>
  4.             canvas{
  5.             }
  6.         </style>
  7.  
  8. <!--- Convert the entire query to an array  Function--->
  9. <cffunction name="queryToArray" access="private" returntype="array" output="false">
  10.         <cfargument name="q" type="query" required="yes" />
  11.         <cfargument name="cb" type="any" required="no" />
  12.         <cfscript>
  13.             var local = {};
  14.             if (structKeyExists(server, "railo")) {
  15.                 local.Columns = listToArray(arguments.q.getColumnList(false));
  16.             }
  17.             else {
  18.                 local.Columns = arguments.q.getMetaData().getColumnLabels();
  19.             }
  20.             local.QueryArray = ArrayNew(1);
  21.             for (local.RowIndex = 1; local.RowIndex <= arguments.q.RecordCount; local.RowIndex++){
  22.                 local.Row = {};
  23.                 local.numCols = ArrayLen( local.Columns );
  24.                 for (local.ColumnIndex = 1; local.ColumnIndex <= local.numCols; local.ColumnIndex++){
  25.                     local.ColumnName = local.Columns[ local.ColumnIndex ];
  26.                     if( local.ColumnName NEQ "" ) {
  27.                         local.Row[ local.ColumnName ] = arguments.q[ local.ColumnName ][ local.RowIndex ];
  28.                     }
  29.                 }
  30.                 if ( structKeyExists( arguments, "cb" ) ) {
  31.                     local.Row = cb( local.Row );
  32.                 }
  33.                 ArrayAppend( local.QueryArray, local.Row );
  34.             }
  35.             return( local.QueryArray );
  36.         </cfscript>
  37.     </cffunction>
  38.  
  39.  
  40.  
  41.  <cfquery name="event_details" dataSource="db9">
  42.                    SELECT nCompetitor as competitor_name, nEvent as event_name, nClass as class_name, nScore as score, nDate as competition_date, nSingle, nTriple, nDouble, nKey
  43.                    FROM nDataAll
  44.                    WHERE nCompetitorID = <cfqueryparam cfsqltype="cf_sql_integer" value="1" />
  45.                    ORDER BY nDate DESC
  46.                </cfquery>
  47.  
  48.  
  49.  
  50. <!--- Convert the entire query to an array of structures --->
  51. <cfset arrEventdetArray = queryToArray( event_details ) />
  52. <!---Show Array --->
  53. <cfdump var="#arrEventdetArray#">
  54.  
  55.  <cfset arrEventDetails = serializeJSON( queryToArray( event_details ) ) />
  56. <cfdump var="#arrEventdetails#">
  57.  
  58.  
  59. <!--- <cfset cats = []>
  60. <cfset data = []>
  61. <cfloop query="event_details">
  62.  
  63.  
  64.  
  65. <cfset arrayAppend(cats, competitor_name)>
  66. <cfset arrayAppend(data, score)>
  67. </cfloop>
  68. --->
  69.  
  70.  
  71. <!---   <cfset arrayAppend(cats, media)>
  72. <cfset arrayAppend(data, total)> --->
  73.  
  74.  
  75.  
  76.  
  77. <body>
  78.     <cfoutput>
  79. <script>
  80.  
  81. var barChartData1 = new Array(ListQualify(ArrayToList(arrEventDetails), '"'));
  82.  
  83.     // var barChartData1 = {
  84.     //      labels : ["January","February","March","April","May","June","July"],
  85.     //      datasets : [
  86.     //          {
  87.     //              fillColor : "rgba(220,220,220,0.5)",
  88.     //              strokeColor : "rgba(220,220,220,1)",
  89.     //              data : [65,59,90,81,56,55,40]
  90.     //          },
  91.     //          {
  92.     //              fillColor : "rgba(151,187,205,0.5)",
  93.     //              strokeColor : "rgba(151,187,205,1)",
  94.     //              data : [28,48,40,19,96,27,100]
  95.     //          }
  96.     //      ]
  97.            
  98.     //  }
  99.  
  100.  
  101. </script>
  102. </cfoutput>
  103.  
  104. <!---[142.4,138.7,138.2,140.8,151.8,140.7,142.0,145.7,151.9,145.8,151.9,142.4,146.5,143.1,152.1,151.6,148.8,152.5,149.1,138.8,142.7,147.0,144.5,141.5,142.5,143.5,143.7,139.9,140.4,142.9,141.8,144.7,141.1,143.1]---->
  105. <div id="chart-container-1" style="width: 400px; height: 400px"></div>
  106.  
  107. </body>
  108.  
  109.  
  110.  
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement