Glad you got it working, and without a peep from anyone else to help you. :) Thanks for the updates, and hopefully this will help others in the future with similar issues.
On Thu, Jul 14, 2016 at 9:33 AM, Niklas Nässén <[email protected]> wrote: > Solved it ! Last trick was the sqldriver, and server tweaking. Attached > you find the result. > > > 1) Installed Apache with PHP, made it as Service. Cheated and used XAMPP > then from the command prompt at the Apache bin subdirectory: httpd.exe -k > install > 2) Installed Sqlsrv SQLSRV32.EXE (I extracted the dll's into php/ext > folder) > 3) Added to php.ini : extension=php_sqlsrv_56_ts.dll > 4) Started Apache > > > Here comes the working code: > > > createJSON.php > > <?php > > include_once 'connection.php'; > > $Tminus0 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-0 hour'))->format('Y-m-d H:i:s'); > $Tminus1 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-1 hour'))->format('Y-m-d H:i:s'); > $Tminus2 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-2 hour'))->format('Y-m-d H:i:s'); > $Tminus3 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-3 hour'))->format('Y-m-d H:i:s'); > $Tminus4 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-4 hour'))->format('Y-m-d H:i:s'); > $Tminus5 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-5 hour'))->format('Y-m-d H:i:s'); > $Tminus6 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-6 hour'))->format('Y-m-d H:i:s'); > $Tminus7 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-7 hour'))->format('Y-m-d H:i:s'); > $Tminus8 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-8 hour'))->format('Y-m-d H:i:s'); > $Tminus9 = date_add(date_create(date("Y-m-d H:00:00")), > date_interval_create_from_date_string('-9 hour'))->format('Y-m-d H:i:s'); > $Interval0 = substr($Tminus0, -8,2) ; > //$Interval1 = substr($Tminus1, -8,2) . "-" . substr($Tminus0, -8,2) ; > //$Interval2 = substr($Tminus2, -8,2) . "-" . substr($Tminus1, -8,2) ; > //$Interval3 = substr($Tminus3, -8,2) . "-" . substr($Tminus2, -8,2) ; > //$Interval4 = substr($Tminus4, -8,2) . "-" . substr($Tminus3, -8,2) ; > //$Interval5 = substr($Tminus5, -8,2) . "-" . substr($Tminus4, -8,2) ; > //$Interval6 = substr($Tminus6, -8,2) . "-" . substr($Tminus5, -8,2) ; > //$Interval7 = substr($Tminus7, -8,2) . "-" . substr($Tminus6, -8,2) ; > //$Interval8 = substr($Tminus8, -8,2) . "-" . substr($Tminus7, -8,2) ; > //$Interval9 = substr($Tminus9, -8,2) . "-" . substr($Tminus8, -8,2) ; > > > > $Interval1 = substr($Tminus1, -8,2) ; > $Interval2 = substr($Tminus2, -8,2) ; > $Interval3 = substr($Tminus3, -8,2) ; > $Interval4 = substr($Tminus4, -8,2) ; > $Interval5 = substr($Tminus5, -8,2) ; > $Interval6 = substr($Tminus6, -8,2) ; > $Interval7 = substr($Tminus7, -8,2) ; > $Interval8 = substr($Tminus8, -8,2) ; > $Interval9 = substr($Tminus9, -8,2) ; > $SQL = "SELECT COUNT(*) as Total FROM [IPS].[dbo].[Loggar_SprLog] where > Loc ='GB03'"; > $SQL9 = " AND Tim >= '" . $Tminus0 . "' AND Tim < '2030-01-01 00:00:00'"; > $SQL8 = " AND Tim >= '" . $Tminus1 . "' AND Tim < '" . $Tminus0 . "'"; > $SQL7 = " AND Tim >= '" . $Tminus2 . "' AND Tim < '" . $Tminus1 . "'"; > $SQL6 = " AND Tim >= '" . $Tminus3 . "' AND Tim < '" . $Tminus2 . "'"; > $SQL5 = " AND Tim >= '" . $Tminus4 . "' AND Tim < '" . $Tminus3 . "'"; > $SQL4 = " AND Tim >= '" . $Tminus5 . "' AND Tim < '" . $Tminus4 . "'"; > $SQL3 = " AND Tim >= '" . $Tminus6 . "' AND Tim < '" . $Tminus5 . "'"; > $SQL2 = " AND Tim >= '" . $Tminus7 . "' AND Tim < '" . $Tminus6 . "'"; > $SQL1 = " AND Tim >= '" . $Tminus8 . "' AND Tim < '" . $Tminus7 . "'"; > $SQL0 = " AND Tim >= '" . $Tminus9 . "' AND Tim < '" . $Tminus8 . "'"; > > $sql = $SQL . $SQL9; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal0 = sqlsrv_get_field( $stmt, 0); > > $sql = $SQL . $SQL8; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal1 = sqlsrv_get_field( $stmt, 0); > > $sql = $SQL . $SQL7; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal2 = sqlsrv_get_field( $stmt, 0); > > $sql = $SQL . $SQL6; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal3 = sqlsrv_get_field( $stmt, 0); > $sql = $SQL . $SQL5; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal4 = sqlsrv_get_field( $stmt, 0); > $sql = $SQL . $SQL4; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal5 = sqlsrv_get_field( $stmt, 0); > $sql = $SQL . $SQL3; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal6 = sqlsrv_get_field( $stmt, 0); > $sql = $SQL . $SQL2; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal7 = sqlsrv_get_field( $stmt, 0); > $sql = $SQL . $SQL1; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal8 = sqlsrv_get_field( $stmt, 0); > > $sql = $SQL . $SQL0; > $stmt = sqlsrv_query( $conn, $sql ); > if( $stmt === false) { > die( print_r( sqlsrv_errors(), true) ); > } > if( sqlsrv_fetch( $stmt ) === false) { > die( print_r( sqlsrv_errors(), true)); > } > $Antal9 = sqlsrv_get_field( $stmt, 0); > > > $rows = array(); > $row9 = array($Interval0, $Antal0); > $row8 = array($Interval1, $Antal1); > $row7 = array($Interval2, $Antal2); > $row6 = array($Interval3, $Antal3); > $row5 = array($Interval4, $Antal4); > $row4 = array($Interval5, $Antal5); > $row3 = array($Interval6, $Antal6); > $row2 = array($Interval7, $Antal7); > $row1 = array($Interval8, $Antal8); > $row0 = array($Interval9, $Antal9); > array_push($rows,$row0); > array_push($rows,$row1); > array_push($rows,$row2); > array_push($rows,$row3); > array_push($rows,$row4); > array_push($rows,$row5); > array_push($rows,$row6); > array_push($rows,$row7); > array_push($rows,$row8); > array_push($rows,$row9); > > print json_encode($rows); > ?> > > > index.php > > <!doctype html > > <?php date_default_timezone_set('Europe/Stockholm');?> > <html lang="en" > > <head> > <meta charset="utf-8" > > <link href="style.css" rel="stylesheet" type="text/css" /> > <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" > > </script> > <!-- Load the AJAX API --> > <script type="text/javascript" src="https://www.google.com/jsapi?autoload= > > {'modules':[{'name':'visualization','version':'1.1','packages': > ['corechart']}]}"></script> > <script type="text/javascript" > > /* Get data from the database */ > function getData() { > jQuery.ajax({ > url: 'createJSON.php', > type: 'GET', > dataType: 'json', > mimeType: 'multipart/form-data', > contentType: false, > cache: false, > processData: false, > success: function( data) { > if( data == "null" ) { > // just in case > } else { > drawGraph( data ); > } > }, > error: function( textStatus ) { > console.log(" error. damm. "); > } > }); > } > > /* Initialization of Google Charts API */ > google.setOnLoadCallback( getData ); > > /* Chart to render time-user graphs */ > function drawGraph( data ) { > for( var i = data.length; i > 0; i-- ) { > data[i] = data[i - 1]; > } > data[0] = [ 'Tid', 'Antal' ]; > var chartData = google.visualization.arrayToDataTable( data ); > var options = { > 'chartArea': {'width': '90%', 'height': '80%'}, > width: 1750, > height: 990, > legend: { position: 'none' }, > vAxis: { gridlines: { count: 8 } }, > > vAxis: { > minValue:0, > maxValue:35, > ticks: [0, 5, 10, 15, 20, 25, 30, 35], > textStyle: {fontSize: 60} > }, > hAxis: {textStyle: {fontSize: 60}} > > > }; > > var chart = new google.visualization.SteppedAreaChart( > document.getElementById( 'chart_div' ) ); > chart.draw( chartData , options ); > } > > setInterval(function(){ > document.getElementById("Tiden").innerHTML = new > Date().toLocaleString(); > getData(); > },1000); > > </script> > </head> > <body> > <div class="chartWithOverlay"> > <div id="chart_div" ></div> > <div class="overlay"> > <div style="font-family:'Arial Black'; font-size: 100px;">GB03</div> > <div style="color: #b44; font-family:'Arial Black'; font-size: 32px; > letter-spacing: .12em; margin-top:0px; margin-left:5px;">Antal producerat > per timma</div> > <div style="color: #444; font-family:'Arial Black'; font-size: 32px; > letter-spacing: .10em; margin-top:0px; margin-left:5px;">ENHET D, IAC Group > AB Skara <div id="Tiden"><?=date('Y-m-d H:i:s', time());?></div></div> > </div> > </div> > </body> > </html> > > Connection.php > > <?php > $serverName = "sksap012\sqlexpress"; //serverName\instanceName > $connectionInfo = array( "Database"=>"IPS", "UID"=>"Excel", > "PWD"=>"XXXXXXX"); > $conn = sqlsrv_connect( $serverName, $connectionInfo); > if( $conn ) { > }else{ > echo "Connection could not be established.<br />"; > die( print_r( sqlsrv_errors(), true)); > } > ?> > > > > style.css > > * { > margin: 0 auto; > padding: 0; > } > > .container { > margin: 0 auto; > width: 1850px; > padding: 20px 20px; > background-color: #fff; > } > h3 { > text-align: center; > } > p { > margin: 0px; > } > #chart_div { > width: 1800px; > height: 1000px; > } > > .chartWithOverlay { > position: relative; > width: 1800px; > } > .overlay { > opacity: 0.3; > width: 700px; > height: 200px; > position: absolute; > top: 60px; > left: 180px; > } > > > -- > You received this message because you are subscribed to the Google Groups > "Google Visualization API" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to > [email protected]. > Visit this group at > https://groups.google.com/group/google-visualization-api. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-visualization-api/67793509-f702-4ede-a81b-1ab8bb93b744%40googlegroups.com > <https://groups.google.com/d/msgid/google-visualization-api/67793509-f702-4ede-a81b-1ab8bb93b744%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> [email protected] <[email protected]> 5CC, Cambridge MA -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-visualization-api. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJMGemLLAaTWD9uELo78THwCCawG3ZuQ7yGnhn%2BSbZ0HFw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
