I have a MSSQL-Database with daily entries. Theses entries are Date and other comments. I want to be count the Date field specific a dynamic week Chart.
My actually problem is to count the Date and write it in my Chart dynamicly.
It would be very nice if somebody could help me, because I have only recently started programming.
HTML:
<div style="width:75%;">
<canvas id="canvas"></canvas>
</div>
<script>
var lineChartData = {
labels: [''],
datasets: [{
label: 'Virenmeldungen',
borderColor: window.chartColors.red,
backgroundColor: window.chartColors.red,
fill: false,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
yAxisID: 'y-axis-1',
}]
};
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d');
window.myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
responsive: true,
hoverMode: 'index',
stacked: false,
title: {
display: true,
text: '' //Chart Überschrift
},
scales: {
yAxes: [{
type: 'linear',
display: true,
position: 'left',
id: 'y-axis-1',
}, {
type: 'linear',
display: true,
position: 'right',
id: 'y-axis-2',
// grid line settings
gridLines: {
drawOnChartArea: false,
},
}],
}
}
});
};
</script>
PHP:
<?php
$server = 'xxxx';
$connInfo = array( "Database"=>"xxxx", "UID"=>"xxxx", "PWD"=>"xxx");
$conn = sqlsrv_connect( $server, $connInfo);
if ( $conn ) {
echo "Die Verbindung wurde aufgebaut.<br />";
}else{
echo "Es konnte keine Verbindung hergestellt werden.<br />";
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT m.time FROM dbo.t_messages m";
$stmt = sqlsrv_query($conn, $sql);
if ( $stmt === false) {
echo "Error";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_fetch($stmt);
$sdate = sqlsrv_get_field($stmt, 0);
if($sdate === false) {
die(print_r(sqlsrv_errors(), true));
}
$date_string = date_format($sdate, 'Y/m/d');
sqlsrv_close( $conn);
?>