Bars
Bars
data
array in the Morris.Bar function to contain the actual data from the database. Here's an example of
how to do that:
php
Copy code
$(document).ready(function() {
$.ajax({
url: 'get_visitor_data.php',
type: 'GET',
dataType: 'json',
success: function(data) {
// Bar Chart
Morris.Bar({
element: 'bar-charts',
data: data,
xkey: 'year',
lineColors: ['#ff9b44','#fc6075'],
lineWidth: '3px',
barColors: ['#ff9b44','#fc6075'],
resize: true,
redraw: true
});
},
console.log(error);
});
});
In this example, we're using an AJAX call to retrieve the data from a PHP script called
get_visitor_data.php, which would contain the SQL query to retrieve the necessary data from the
database. The data returned from the PHP script is in JSON format, which is then passed to the data
array in the Morris.Bar function.
The data returned from the PHP script should be in the following format:
yaml
Copy code
The xkey property should correspond to the year field in the data, and the ykeys property should
correspond to the total_income and total_outcome fields.
use my above details to change details just use visitor system so the charts will check the total user
as per day,per week,per month, and per year..
Sure, here's an example code that retrieves data from the visitor table to display the total number of
visitors per day, per week, per month, and per year. The code uses the Chart.js library for creating
charts.
php
Copy code
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
$.ajax({
url: 'retrieve_visitor_data.php',
dataType: 'json',
success: function(data) {
visitorsPerDay.push(data[i].visitors);
var visitors = 0;
if (moment(data[j].date).format('YYYY-MM-DD') == weekDay) {
visitors = data[j].visitors;
break;
}
}
visitorsPerWeek.push(visitors);
var visitors = 0;
if (moment(data[j].date).format('YYYY-MM-DD') == monthDay) {
visitors = data[j].visitors;
break;
visitorsPerMonth.push(visitors);
var visitors = 0;
if (moment(data[j].date).format('YYYY-MM-DD') == yearDay) {
visitors = data[j].visitors;
break;
}
visitorsPerYear.push(visitors);
type: 'bar',
data: {
datasets: [{
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}]
});
});
</script>
<div class="col-md-12">
<div class="row">
<div class="card">
<div class="card-
body">
<h3
class="card-title">Total Visitors</h3>
<div
id="bar-charts"></div>
</div>
</div>
</div>
Consider the above code and the below javascript i need those bar to retrieve data from database
consider visitor table
$(document).ready(function() {
// Bar Chart
Morris.Bar({
element: 'bar-charts',
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }
],
xkey: 'y',
lineColors: ['#ff9b44','#fc6075'],
lineWidth: '3px',
barColors: ['#ff9b44','#fc6075'],
resize: true,
redraw: true
});
// Line Chart
Morris.Line({
element: 'line-charts',
data: [
{ y: '2006', a: 50, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 50 }
],
xkey: 'y',
lineColors: ['#ff9b44','#fc6075'],
lineWidth: '3px',
resize: true,
redraw: true
});
});
To retrieve data from the database and display it in the Morris Bar Chart, you need to use AJAX to
fetch the data from the server. Here's an updated version of the JavaScript code with AJAX
integration:
php
Copy code
$(document).ready(function() {
// Bar Chart
$.ajax({
url: '/get-visitors-data',
dataType: 'json',
success: function(data) {
Morris.Bar({
element: 'bar-charts',
data: data,
xkey: 'y',
lineColors: ['#ff9b44','#fc6075'],
lineWidth: '3px',
barColors: ['#ff9b44','#fc6075'],
resize: true,
redraw: true
});
}
});
// Line Chart
$.ajax({
url: '/get-visitors-data',
dataType: 'json',
success: function(data) {
Morris.Line({
element: 'line-charts',
data: data,
xkey: 'y',
lineColors: ['#ff9b44','#fc6075'],
lineWidth: '3px',
resize: true,
redraw: true
});
});
});
In this code, we are making an AJAX call to the /get-visitors-data URL to fetch the visitor data from
the server. The server should return the data in JSON format, which will be used to populate the
Morris Bar and Line charts.
You need to implement a server-side endpoint that returns the visitor data in the expected format.
The visitor data should include the total number of visitors and outcomes for each day, week,
month, and year. You can use the following example data format:
yaml
Copy code
[
{ y: '2022-03-10', a: 100, b: 90 },
{ y: '2022-03-09', a: 75, b: 65 },
{ y: '2022-03-08', a: 50, b: 40 },
{ y: '2022-03-07', a: 75, b: 65 },
{ y: '2022-03-06', a: 50, b: 40 },
{ y: '2022-03-05', a: 75, b: 65 },
{ y: '2022-03-04', a: 100, b: 90 }
The y property represents the date, while a and b represent the total number of visitors and
outcomes for that date, respectively. The date format can be changed as per your requirement.
I apologize for the confusion. The code you provided earlier was only HTML and JavaScript. To
retrieve data from a database, you would need to use PHP to make a server-side request to the
database and retrieve the data.
Here's an example PHP code snippet that you could use to retrieve data from a MySQL database:
php
Copy code
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
if (!$conn) {
// Perform query
$data = array();
$data[] = $row;
// Close connection
mysqli_close($conn);
echo json_encode($data);
?>
You would need to replace the $servername, $username, $password, and $dbname variables with
your own database credentials. You would also need to modify the $sql query to match your
database schema.
You could then use the $.ajax() function in JavaScript to make a request to this PHP script and
retrieve the data as a JSON object.
[email protected]
nataka wewe unitengenezee mfano wa javascript code na php ambazo zitakuwa zina vuta data
kutoka kwenye database na kuzionyesha kwa bar charts ambazo nimekupa nataka bars zionyeshe
jumla ya visitor kwa mwaka,mwezi,wiki tumia taarifa za boostrap na javascript ambazo nilikuwa
nimekupatia kabla..
"I want you to create an example of JavaScript code and PHP that will retrieve data from the
database and display it in bar charts using the charts that I provided. I want the bars to show the
total number of visitors per year, month, and week. Please use the Bootstrap and JavaScript
information that I provided before."
I want you to create an example of JavaScript code and PHP that will retrieve data from the database
and display it in bar charts using the charts that I provided. I want the bars to show the total number
of visitors per year, month, and week. Please use the Bootstrap and JavaScript information that I
provided before.
Sure, here's an example of JavaScript code and PHP that will retrieve data from a MySQL database
and display it in bar charts using the provided charts, showing the total number of visitors per year,
month, and week:
index.php:
html
Copy code
<!DOCTYPE html>
<html>
<head>
<title>Visitor Charts</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.3.0/raphael.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="card">
<div class="card-body">
<h3 class="card-title">Total
Visitors</h3>
<div id="bar-charts"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
script.js:
javascript
Copy code
$(document).ready(function() {
$.ajax({
url: 'data.php',
dataType: 'json',
success: function(data) {
// Bar Chart
Morris.Bar({
element: 'bar-charts',
data: data.bar_data,
xkey: 'date',
ykeys: ['visitors'],
barColors: ['#ff9b44'],
resize: true,
redraw: true
});
// Line Chart
Morris.Line({
element: 'line-charts',
data: data.line_data,
xkey: 'date',
ykeys: ['visitors'],
lineColors: ['#fc6075'],
lineWidth: '3px',
resize: true,
redraw: true
});
}
});
});
data.php:
php
Copy code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";
if (!$conn) {
$bar_data = array();
$sql = "SELECT DATE_FORMAT(date, '%Y-%m-%d') as date, COUNT(*) as visitors FROM visitor GROUP
BY DATE_FORMAT(date, '%Y-%m-%d')";
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$bar_data[] = $row;
$line_data = array();
$sql = "SELECT DATE_FORMAT(date, '%Y-%m') as date, COUNT(*) as visitors FROM visitor GROUP BY
[email protected]
your so mad you didn't finish the code you make me to feel anger
I apologize if my previous response did not fully address your request. Here is an example of a PHP
and JavaScript code that retrieves data from a MySQL database and displays it in bar charts using the
Morris.js library:
PHP Code:
php
Copy code
<?php
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$database = 'your_database';
$year_data = array();
$month_data = array();
$week_data = array();
$sql = "SELECT YEAR(date) AS year, COUNT(*) AS count FROM visitors GROUP BY YEAR(date) ORDER
BY YEAR(date) ASC";
$result = $conn->query($sql);
$sql = "SELECT CONCAT(YEAR(date), '-', MONTH(date)) AS month, COUNT(*) AS count FROM visitors
GROUP BY YEAR(date), MONTH(date) ORDER BY YEAR(date) ASC, MONTH(date) ASC";
$result = $conn->query($sql);
$result = $conn->query($sql);
$conn->close();
?>
JavaScript Code:
javascript
Copy code
$(document).ready(function() {
Morris.Bar({
element: 'bar-chart-year',
data: <?php echo json_encode($year_data); ?>,
xkey: 'y',
ykeys: ['a'],
barColors: ['#ff9b44'],
resize: true,
redraw: true
});
Morris.Bar({
element: 'bar-chart-month',
xkey: 'y',
ykeys: ['a'],
barColors: ['#ff9b44'],
resize: true,
redraw: true
});
Morris.Bar({
element: 'bar-chart-week',
xkey: 'y',
ykeys: ['a'],
barColors: ['#ff9b44'],
resize: true,
redraw: true
});
});
Please note that you will need to replace the database credentials and table name in the PHP code
with your own. Also, make sure to include the Morris.js library and the jQuery library in your HTML
file.
In this article, we will learn how to show success message after completing a task.
You will learn how to use sessions in php and use sessions to set the flash message
and display them after success.
Note : To use session in any page, we need to start the session on top of the
page using the session_start();
After inserting / updating the data in the database, set the session message in a
session variable as shown below:
<?php
session_start();
//after insert or update
$_SESSION['status'] = "<Type Your success message here>";
?>
Now we have set the message and now paste the below code in the page where you
want display the success message :
Note : Import the Bootstrap v5 CSS and JS using the cdn link available on
getboostrap.com, for good design and results as shown in the above video.
<?php
session_start();
if(isset($_SESSION['status']))
{
?>
<div class="alert alert-warning alert-dismissible fade show" rol
e="alert">
<strong>Hey !</strong> <?= $_SESSION['status']; ?>
<button type="button" class="btn-close" data-bs-
dismiss="alert" aria-label="Close"></button>
</div>
<?php
unset($_SESSION['status']);
}
?>
5997@asna
Asna@5997
Privacy Policy
Introduction
Our visitor information system (the "Service") is provided by XYZ Corporation ("we," "us," "our"). We
are committed to protecting the privacy of our users ("you," "your"). This privacy policy ("Policy")
describes how we collect, use, and disclose personal information about users of the Service.
Contact information, such as your name, email address, and phone number.
We use reasonable measures to protect your personal information from unauthorized access,
disclosure, alteration, and destruction. However, no security measure is completely secure, so we
cannot guarantee the security of your information.
Your rights
You have the right to access and control your personal information. You can do this by contacting us
at [email protected]. You also have the right to lodge a complaint with a data protection
authority.
We may update this Policy from time to time. If we make material changes, we will notify you by
email or by posting a notice on the Service prior to the change becoming effective.
Contact Us
If you have any questions or concerns about this Policy, please contact us at [email protected].