Here's a complete example of a dashboard with one panel using Tailwind CSS and the AmCharts 5 library to display a line chart with random data. This example uses CDN links for simplicity and assumes no build tools.
✅ Features:
- Single panel layout using Tailwind CSS
- Line chart with random data points
- Responsive and styled using Tailwind
📄 Full HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AmCharts Dashboard</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- AmCharts 5 CDN -->
<script src="https://cdn.jsdelivr.net/npm/@amcharts/amcharts5@5.3.0/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@amcharts/amcharts5-xy@5.3.0/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@amcharts/amcharts5/themes/Animated.js"></script>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
<div class="w-full max-w-4xl p-6">
<!-- Dashboard Panel -->
<div class="bg-white shadow-lg rounded-lg p-6">
<h2 class="text-xl font-semibold mb-4">Random Line Chart</h2>
<div id="chart" class="h-96"></div>
</div>
</div>
<script>
// Generate random data
const data = [];
for (let i = 0; i < 10; i++) {
data.push({
x: i,
y: Math.random() * 100
});
}
// Initialize AmCharts
am5.ready(function () {
// Create root
const root = am5.Root.new("chart");
// Set themes
root.setThemes([am5themes_Animated.new(root)]);
// Create chart
const chart = root.container.children.push(
am5xy.XYChart.new(root, {
panX: false,
panY: false,
wheelX: "panX",
wheelY: "zoomX"
})
);
// Create axes
const xAxis = chart.xAxes.push(
am5xy.ValueAxis.new(root, {
min: 0,
max: 9,
strictMinMax: true,
renderer: am5xy.AxisRendererX.new(root, {})
})
);
const yAxis = chart.yAxes.push(
am5xy.ValueAxis.new(root, {
min: 0,
max: 100,
strictMinMax: true,
renderer: am5xy.AxisRendererY.new(root, {})
})
);
// Create line series
const series = chart.series.push(
am5xy.LineSeries.new(root, {
name: "Series 1",
xAxis: xAxis,
yAxis: yAxis,
data: data,
connect: false
})
);
// Add bullets
series.bullets.push(function () {
return am5xy.Bullet.new(root, {
sprite: am5.Circle.new(root, {
fill: am5.color(0xff0000),
radius: 5
})
});
});
// Add cursor
chart.set("cursor", am5xy.Cursor.new(root, {}));
// Set initial data
series.data.setAll(data);
});
</script>
</body>
</html>
🔧 How It Works:
- Tailwind CSS is used for layout and styling (e.g.,
bg-white, shadow-lg, rounded-lg).
- AmCharts 5 is used to render the line chart.
- Random data is generated using a simple loop, with
x as the index and y as a random number between 0 and 100.
- The chart is embedded in a
div with id="chart" and a fixed height of h-96 (384px).
🧪 To Use:
- Save the code above as an
.html file.
- Open it in your browser.
- You'll see a clean dashboard with a line chart displaying random data points.
Let me know if you'd like to add interactivity, tooltips, or dynamic updates!