Pie Chart from Columns in a DataFrame
Multiple Pie Chart from Columns in a DataFrame
Copy <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="plot_div"></div>
<script>
const df = new dfd.DataFrame({
Price: [19, 26, 55],
Volume: [100, 200, 300],
Location: ["NG", "GH", "SA"],
Type: ["Residential", "Non-Residential", "Utility"],
});
df.plot("plot_div").pie({
config: {
labels: "Location",
columns: ["Price", "Volume"],
columnPositions: [0, 1],
}
});
</script>
</body>
</html>
If you have more than one pie chart to display, you can set the grid parameter, and also the position of each pie.
Copy <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="plot_div"></div>
<script>
df = new dfd.DataFrame({
Price: [19, 26, 55],
Count: [20, 50, 25],
Type: ['Residential', 'Non-Residential', 'Utility']
})
df.plot("plot_div").pie({
config: {
labels: "Location",
columns: ["Price", "Volume"],
columnPositions: [0, 1],
rowPositions: [0, 1],
grid: { rows: 2, columns: 2 }
}
});
</script>
</body>
</html>