Morris.js Dynamic Data Example PHP Mysql

Today, We want to share with you Morris.js Dynamic Data Example PHP Mysql.In this post we will show you Display line and area charts in PHP and MySQL, hear for Create Charts and Graphs Using MySQL, PHP, Morris.js Tutorial we will give you demo and example for implement.In this post, we will learn about How to convert MySQL query to Morris chart readable json with an example.Blogs – Pakainfo.com

Morris.js Dynamic Data Example PHP Mysql

There are the Following The simple About Morris.js Dynamic Data Example PHP Mysql Full Information With Example and Pakainfo.com source code.

As I will cover this Post with live Working example to develop javascript – Morris chart with dynamic data using PHP MySQL, so the some major files and Directory structures for this example is following below.Free Download Example – Pakainfo.com

Step 1: Morris Area Chart Code

var Area_chart = Morris.Area({
 	element: 'Area_chart', 
 	behaveLikeLine: true,
 	parseTime : false, 
	data: [{ y: '2006', a: 100, b: 90 },
 		{ y: '2007', a: 75, b: 65 },
 		{ y: '2008', a: 50, b: 40 },
 		{ y: '2019', a: 75, b: 65 },
 		{ y: '2020', a: 50, b: 40 },
 		{ y: '2021', a: 75, b: 65 },
 		{ y: '2022', a: 100, b: 90 }],
 	xkey: 'y',
 	ykeys: ['a', 'b'],
 	labels: ['Sales', 'Cost'],
 	pointFillColors: ['#707f9b'],
 	pointStrokeColors: ['#ffaaab'],
 	lineColors: ['#f26c4f', '#00a651', '#00bff3'],
 	redraw: true, 
 });

Step 2: jQuery Ajax Call

Simple jQuery Ajax Call Source code

$("#Types").on("change", function(){
 	var type = $(this).val(); 
 	$.ajax({
 		type: "POST",
 		url: "ajax.php?type="+type,
 		data: 0,
 		dataType: 'json',
 		success: function(data){
 			console.log(data);
 			Area_chart.setData(data);  //Simple data Helps to recreate your chart with result data's
 		}
 	});
 });

Step 3: PHP Function

simple PHP Source code

<?php if(isset($_GET['type'])){  
	if($_GET['type'] == 1){
		$live_place_area =array(  array( 'y' => "2021" , 'a' => 3, 'b' => 6 ) ,  array( 'y' => "2021 Q2" , 'a' => 10, 'b' => 1 ) ,  array( 'y' => "2021 Q3" , 'a' => 2 , 'b' => 4) ,  array( 'y' => "2021 Q4" , 'a' => 3 , 'b' => 3)  );
	}elseif($_GET['type'] == 2){ 
		$live_place_area =array(  array( 'y' => "2021" , 'a' => 20, 'b' => 60 ) ,  array( 'y' => "2022" , 'a' => 18, 'b' => 21 ) ,  array( 'y' => "2021" , 'a' => 32 , 'b' => 74) ,  array( 'y' => "2014" , 'a' => 38 , 'b' => 63)  );
	}
	echo json_encode($live_place_area); exit; 
}
?>

Our customers made these Tricks for improving – Pakainfo.com System.
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Morris.js Dynamic Data Example PHP Mysql.
I would like to have feedback on my My Blog pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel delete foreign key Constraint Using Migration
  2.   Google API Line Chart with JSON PHP & Mysql
  3.   Solution for "Trying to get property of non-object" in Laravel
  4.   Latest Top 10 jQuery Interview Questions and Answers
  5.   PHP cURL Multiple Asynchronous Http Requests
  6.   PHP LinkedIn Authentication AccessToken - LinkedIn OAuth 2.0
  7.   How to Create CAPTCHA image verification using PHP and jQuery
  8.   Update Scope Variable using Angular Example
  9.   Get Parent Elements With CSS and jQuery
  10.   Connect Multiple Databases in CodeIgniter