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?


$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>
<title>Webslesson Tutorial | How to use Morris.js chart with PHP & Mysql</title>
<link rel="stylesheet" href="//">
<script src="//"></script>
<script src="//"></script>
<script src="//"></script>

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

element: 'chart',
data:[<?php echo $chart_data; ?>],
xkey: 'ID',
ykeys: ['Wrongs', 'Rights'],
labels: ['Wrongs', 'Rights'],

Options: ReplyQuote

Written By
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.