I create a website using php and i have a dashboard. In my dashboard i have a chart i used Highcharts to render my data. I have a problem in displaying my data. Yes i can display the data in the Highcharts but i cannot display it correctly. I think i have problem in my query.
As you can see in my dashboard. August 1, 2017 is the latest date, but its location is in the older. Now i want is the latest date is in the front or before the older date.
This is my query:
<?php
require_once('includes/database.php');
$stmt = mysqli_prepare($con, "SELECT date_format(entry_date, '%d-%b-%y')
as pDate, sum(doc_count) as pAmount FROM report_details GROUP BY pDate
DESC");
$result = array('day' => array(), 'amount' => array());
if ($stmt) {
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $day, $amount);
while (mysqli_stmt_fetch($stmt)) {
$result['day'][] = $day;
$result['amount'][] = (int)$amount;
}
mysqli_stmt_close($stmt);
}
?>
And this is my Highcharts:
<script type="text/javascript">
window.onload = function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
backgroundColor: {
linearGradient: [0, 0, 500, 500],
stops: [
[0, 'rgb(38,50,56)'],
[1, 'rgb(84,110,122)']
]
},
type: 'line',
borderColor: '#37474f',
borderWidth: 2,
},
title: {
text: 'Document Saved Per day',
style:{
font: 'bold 25px "Trebuchet MS", Verdana, sans-serif',
color: 'white'
}
},
xAxis: {
max:13,
categories: <?php echo json_encode($result['day']) ?>,
crosshair: true,
labels: {
style: {
color: 'white',
font: 'bold 13px "Trebuchet MS", Verdana, sans-serif'
}
}
},
yAxis: {
min:0,
max:100,
labels: {
style: {
color: 'white',
fontSize: '15px'
}
},
gridLineColor: 'white',
title: {
text:'Documents',
style: {
color:'white',
font: 'bold 20px "Trebuchet MS", Verdana, sans-serif'
}
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
color: '#85DEFC',
name: 'Documents',
data: <?php echo json_encode($result['amount']) ?>
}]
});
};
</script>
I got the answer. I thought it is very difficult but its not.
This is my answer:
<?php
require_once('includes/database.php');
$stmt = mysqli_prepare($con, "SELECT date_format(entry_date, '%d-%b-%y'),
sum(doc_count) as pAmount FROM report_details GROUP BY entry_date
DESC");
$result = array('day' => array(), 'amount' => array());
if ($stmt) {
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $day, $amount);
while (mysqli_stmt_fetch($stmt)) {
$result['day'][] = $day;
$result['amount'][] = (int)$amount;
}
mysqli_stmt_close($stmt);
}
?>
I delete the alias 'pDate' and used the 'entry_date' to my query, and it works for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.