MySQL Forums
Forum List  »  PHP

Morris.js Bar Graph in php?
Posted by: Mohammed Saif
Date: March 05, 2020 04:09AM

I am using Morris.js graphs to display my MySQL data. Unfortunately the graphs are not visible at all. I have followed a simple tutorial and still nothing happens. What am I doing wrong in the code? I am assuming that the data format under Morris.Bar code should be different. What should the format be?

<?php

$connect = mysqli_connect("localhost", "host", "", "_data");
$query = "SELECT * FROM Datas";
$result = mysqli_query($connect, $query);
$chart_data = '';

while($row = mysqli_fetch_array($result))
{
$chart_data .= "{ ID:'".$row["ID"]."', Name:".$row["Name"].", Wrongs:".$row["Wrongs"].", Rights:".$row["Rights"].", Percentage:".$row["Percentage"].", Age:".$row["Age"]."}, ";
}
$chart_data = substr($chart_data, 0);
?>

<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | How to use Morris.js chart with PHP & Mysql</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>

</head>
<body>
<br /><br />
<div class="container" style="width:900px;">
<h2 align="center">MySQL</h2>
<h3 align="center">Data</h3>
<br /><br />
<div id="chart"></div>
</div>
</body>
</html>


<script>
Morris.Bar({
element: 'chart',
data:[<?php echo $chart_data; ?>],
xkey: 'ID',
ykeys: ['Wrongs', 'Rights'],
labels: ['Wrongs', 'Rights'],
});
</script>

Options: ReplyQuote


Subject
Written By
Posted
Morris.js Bar Graph in php?
March 05, 2020 04:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.