JavaScript Graph
Posted by Superadmin on May 03 2023 15:03:14

JavaScript Graph

JavaScript Graph

Introduction to JavaScript Graph

In JavaScript, graph is one of the technology method for generating charts and mainly its requires to some little techniques but it does not depend on the coding parts. When we use js charts in web applications it has user-friendly and a very simple easy task for the client user to understand the concepts meanwhile. It depends on the client-side scripting technique i.e. it is performed only by the user browsers there is no extra or additional plugins for related with the any type of modules etc is going to be required we can include only the script and prepare the data with any type of languages called xml, json, javascript arrays etc.

Syntax and Parameters:

When we use the graph in script mainly it depends on x-axis, y-axis and z-axis based on the user requirements.

<script>
function name()
{
var v1=new CanvasJS.chart(“”,{
-----some script logics ------
x-axis:
{
}
y-axis:
{
}
z-axis:
{
}
}
</script>

We can call the function with a different set of axis among these CanvasJS is one of the default class and it uses the method like Chart() while we passed the arguments as x, y and z-axis.

How is Graph done in JavaScript?

Examples of JavaScript Graph

Given below are the examples of JavaScript Graph:

Example #1

Code:

<html>
<script type="text/javascript">
window.onload = function () {
var c = new CanvasJS.Chart("first", {
title:{
text: "Have a Nice Day"
},
data: [
{
type: "column",
dataPoints: [
{ label: "siva",  y: 9  },
{ label: "raman", y: 17  },
{ label: "arun", y: 26  },
{ label: "kumar",  y: 33 },
{ label: "gdgs",  y: 29  }
]
}
]
});
c.render();
}
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"> </script>
<body>
<div id="first" style="height: 302px; width: 103%;"></div>
</body>
</html>

Output:

JavaScript Graph 1

Example #2

Code:

<html>
<script type="text/javascript">
window.onload = function () {
var c = new CanvasJS.Chart("first",
{
zoomEnabled: true,
title:{
text: "Welcome User Today updated dates and time are"
},
data: [
{
type: "area",
xValueType: "dateTime",
dataPoints: [
{ x: 1185622200000, y :72},
{ x: 1285622200000, y : 54 },
{ x: 1383622200000, y:  57 },
{ x: 1485622200000, y : 64 },
{ x: 1585622200000, y : 98 },
]
}
]
});
c.render();
}
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<body>
<div id="first" style="height: 303px; width: 103%;">
</div>
</body>
</html>

Output:

JavaScript Graph 2

Example #3

Code:

<html>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("first",
{
zoomEnabled: true,
title:{
text: "Welcome To My Domain"
},
axisY:{
includeZero: false
},
data: data,
});
chart.render();
}
var l = 2000;
var y = 0;
var data = []; var ds = { type: "line" };
var dataPoints = [];
for (var i = 0; i < l; i += 1) {
y += (Math.random() * 10 - 5);
dataPoints.push({
x: i - l / 2,
y: y
});
}
ds.dataPoints = dataPoints;
data.push(ds);
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<body>
<div id="first" style="height: 302px; width: 103%;">
</div>
</body>
</html>

Output:

Welcome To My Domain

Conclusion

The charts are the way to understand the customer datas or any other useful scenarios in easy way. It is one of the user-friendly method with the browser interaction. It also supported all type of default browser in default Canvas JS file is added to the script.