我有一个MSSQL数据库,其中包含每日条目。这些条目是日期和其他注释。我想计算特定于动态星期图表的日期字段。
我的实际问题是要计算日期并动态地将其写入图表中。
如果有人可以帮助我,那将非常好,因为我是最近才开始编程的。
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);
?>