Chart Creation
Design the form

1. Open  the editor (e.g. Notepad++).

2. Type the following  code  in the editor.

3. Create a folder  “chart”  in the  path  “C:\wamp\www”.
4. Save the file as “form.php” in the  “chart” folder.        
5. Start the WAMP  server. Open the browser and enter the following URL:
                http://localhost/chart/form.php
image 2022 11 11 063542339
Create a table in MySQL datatabe
6. Login  to the phpMyAdmin  interface  by  entering the  ” username : root ” and click  “Go”  button.
image 2022 11 11 064501819
7. Create the database  “chartdb”.
8. In the database, create a table “cricket”  with  three columns(pid  int(11) AUTO_INCREMENT, player  varchar(40), wickets   int(5)).
table
Download canvas.min.js

9. Download the javascript file  “canvas.min.js”  from the following URL:                                                   https://www.cdnpkg.com/canvasjs/file/canvas.min.js/?id=26465

10.Create the folder “js”  in the following path :
     C:\wamp\www\chart\
11.Copy and paste the  javascript file within the folder “js”.
12.Specify the  script file  in  <head>  as:
     <script src=”/chart/js/canvasjs.min.js”>  </script>

Note: Instead of  downloading  javascript file, If we are in online then we can also add the HTML  snippet with in the <head> as:

<script type=”text/javascript” src=”https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.4.1/canvas.min.js”></script>

Create the Chart

13. Type the following code in the editor to create the chart.

Copy

<?php
mysql_connect(“localhost”,”root”,””);
mysql_select_db(“chartdb”);
$d=mysql_query(“select * from cricket”);
$dp=array();
while($r=mysql_fetch_array($d))
{
$p=array(“label”=>$r[1],”y”=>$r[2]);
array_push($dp,$p);
}
?>

<!DOCTYPE HTML>
<html>
<head>
<style>
a
{
position:absolute;
top:150px;
left:10px;
text-decoration:none;
font-weight:bold;
color:green;
}
#c
{
position:absolute;
top:20px;
left:300px;
width:1000px;
height:600px;
}
</style>
<script src=”/chart/js/canvasjs.min.js”></script>
<script type=”text/javascript”>
window.onload=function()
{
var ch=new CanvasJS.Chart(“c”,
{
theme:”light1″,//light2,dark1,dark2
animationEnabled:true,
showInLegend: true,
title:{text:”Players and Wickets”,fontColor: “#008B8B”,fontSize: 32},
axisX:{title:”Players”,titleFontColor: “green”,labelAngle: -30},
axisY:{title:”Wickets”,titleFontColor: “green”},
data:[{type:”column”,//bar,spline,area,pie,doughnut,line
dataPoints:<?php echo json_encode($dp,JSON_NUMERIC_CHECK); ?>
}]
});
ch.render();
}
</script>
</head>
<body>
<a href=”/chart/form.php”>Click here to enter the data</a>
<div id=”c”></div>
</body>
</html>

14. Save the file as “display.php” in the same  “chart” folder.        
Run the Program
15. Finally, enter the inputs in the “form.php” and click the “Enter” button.        
image 2022 11 13 234809402
16. After inserting the new record, “success” message will be displayed.
17. Now, click the link “Click here to display the chart”.
image 2022 11 13 235635366
Spread the code...