Vue 2 数据可视化仪表盘:创建动态图表与互动数据展示 前端实战:用 Vue 2 构建数据仪表盘,轻松实现图表展示 Vue 2 数据仪表盘开发:响应式设计与动态数据展示案例 前端新手必看:用 Vue
发布时间
阅读量:
阅读量
效果图

🌟【定制化开发服务,让您的项目领先一步】🌟
如有需求,直接私信留下您的联系方式。谢谢。
我的邮箱:2351598671@qq.com
完整代码
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue 2 数据可视化仪表盘</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background: #f4f4f4;
color: #333;
line-height: 1.6;
}
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 40px;
}
.header-title {
font-size: 2.5rem;
color: #5a5a5a;
margin-bottom: 10px;
}
.header-subtitle {
font-size: 1.2rem;
color: #777;
}
.card {
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
text-align: center;
margin: 15px;
flex: 1;
transition: transform 0.3s ease;
}
.card:hover {
transform: scale(1.05);
}
.card h3 {
margin-bottom: 10px;
color: #4b4b4b;
}
.card p {
font-size: 1.1rem;
color: #777;
}
.card .value {
font-size: 2rem;
color: #007BFF;
margin-bottom: 15px;
}
.card .icon {
font-size: 3rem;
color: #007BFF;
margin-bottom: 10px;
}
.chart-container {
margin-top: 40px;
position: relative;
width: 100%;
height: 300px;
}
.news-section {
margin-top: 40px;
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.news-title {
font-size: 2rem;
margin-bottom: 15px;
color: #4b4b4b;
}
.news-item {
display: flex;
justify-content: space-between;
padding: 15px;
border-bottom: 1px solid #ddd;
}
.news-item:last-child {
border-bottom: none;
}
.news-item a {
text-decoration: none;
color: #007BFF;
font-size: 1rem;
}
.news-item .date {
color: #777;
font-size: 0.9rem;
}
.row {
display: flex;
justify-content: space-between;
}
@media (max-width: 768px) {
.row {
flex-direction: column;
}
.card {
margin-bottom: 20px;
}
.chart-container {
height: 250px;
}
}
</style>
</head>
<body>
<div id="app" class="container">
<header>
<h1 class="header-title">Vue 2 数据可视化仪表盘</h1>
<p class="header-subtitle">轻松展示和分析数据</p>
</header>
<div class="row">
<div class="card">
<div class="icon">📈</div>
<h3>总销售额</h3>
<p>最新的销售数据</p>
<div class="value">{{ totalSales }}</div>
</div>
<div class="card">
<div class="icon">🛒</div>
<h3>订单数量</h3>
<p>总订单数</p>
<div class="value">{{ totalOrders }}</div>
</div>
<div class="card">
<div class="icon">👨💻</div>
<h3>活跃用户</h3>
<p>每日活跃用户数量</p>
<div class="value">{{ activeUsers }}</div>
</div>
</div>
<div class="chart-container">
<canvas id="salesChart"></canvas>
</div>
<section class="news-section">
<h2 class="news-title">最新新闻</h2>
<div class="news-item" v-for="news in newsItems" :key="news.id">
<div>
<a :href="news.url" target="_blank">{{ news.title }}</a>
</div>
<div class="date">{{ news.date }}</div>
</div>
</section>
</div>
<script>
new Vue({
el: '#app',
data: {
totalSales: "$15,000",
totalOrders: 350,
activeUsers: 1200,
newsItems: [
{ id: 1, title: 'Vue 3 发布新版本', date: '2025-01-01', url: 'https://vuejs.org/' },
{ id: 2, title: '前端开发趋势2025', date: '2025-01-02', url: 'https://www.frontendtrends.com/' },
{ id: 3, title: 'JavaScript 性能优化技巧', date: '2025-01-03', url: 'https://www.javascript.com/' }
]
},
mounted() {
var ctx = document.getElementById('salesChart').getContext('2d');
var salesChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['1月', '2月', '3月', '4月', '5月', '6月'],
datasets: [{
label: '月销售额',
data: [1200, 1900, 1500, 2200, 3000, 2800],
borderColor: '#007BFF',
backgroundColor: 'rgba(0, 123, 255, 0.2)',
fill: true,
tension: 0.4
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(tooltipItem) {
return '$' + tooltipItem.raw;
}
}
}
}
}
});
}
});
</script>
</body>
</html>
全部评论 (0)
还没有任何评论哟~
