JavaScript libraries to use for both Artificial Intelligence graphs and other charts:
Plotly.js is a charting library that comes with over 40 chart types, 3D charts, statistical graphs, and SVG maps.
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
Chart.js comes with many built-in chart types:
Scatter
Line
Bar
Radar
Pie and Doughnut
Polar Area
Bubble
Chart.js is easy to use.
First, add a link to the providing CDN (Content Delivery Network):
<script
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js">
</script>
Then, add a <canvas> to where you want to draw the chart:
<canvas id="myChart" style="width:100%;max-width:700px"></canvas>
The canvas element must have a unique id.
That's all!
From simple line charts to complex hierarchical tree maps, the Google Chart gallery provides a large number of ready-to-use chart types:
Scatter Chart
Line Chart
Bar / Column Chart
Area Chart
Pie Chart
Donut Chart
Org Chart
Map / Geo Chart
How to Use Google Chart?
To use Google Chart in your web page, add a link to the charts loader:
<script
src="https://www.gstatic.com/charts/loader.js">
</script>
Google Chart is easy to use.
Just add a <div> element to display the chart:
<div id="myChart" style="max-width:700px; height:400px"></div>
The <div> element must have a unique id.
Then load the Google Graph API:
Load the Visualization API and the corechart package
Set a callback function to call when the API is loaded
google.charts.load('current',{packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
That's all!
Bootstrap
index.html
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<div id="myPlot" style="width:100%;max-width:700px"></div>
<script>
var xArray = [50,60,70,80,90,100,110,120,130,140,150];
var yArray = [7,8,8,9,9,9,10,11,14,14,15];
// Define Data
var data = [{
x:xArray,
y:yArray,
mode:"markers"
}];
// Define Layout
var layout = {
xaxis: {range: [40, 160], title: "Square Meters"},
yaxis: {range: [5, 16], title: "Price in Millions"},
title: "House Prices vs. Size"
};
// Display using Plotly
Plotly.newPlot("myPlot", data, layout);
</script>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
-->
</body>
</html>