<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>H5产品月销售额柱状图表 - 更多源码【www.96flw.com】</title>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="css/tailwind.min.css" rel="stylesheet">
<script src="js/alpine.min.js" type="text/javascript"></script>
<style>
body {
font-family: 'IBM Plex Mono', sans-serif;
}
[x-cloak] {
display: none;
}
.line {
background: repeating-linear-gradient(
to bottom,
#eee,
#eee 1px,
#fff 1px,
#fff 8%
);
}
.tick {
background: repeating-linear-gradient(
to right,
#eee,
#eee 1px,
#fff 1px,
#fff 5%
);
}
</style>
</head>
<body class="antialiased sans-serif bg-gray-200">
<div x-data="app()" x-cloak class="px-4">
<div class="max-w-lg mx-auto py-24">
<div class="shadow p-6 rounded-lg bg-white">
<div class="md:flex md:justify-between md:items-center">
<div>
<h2 class="text-xl text-gray-800 font-bold leading-tight">产品销售</h2>
<p class="mb-2 text-gray-600 text-sm">月平均</p>
</div>
<!-- Legends -->
<div class="mb-4">
<div class="flex items-center">
<div class="w-2 h-2 bg-blue-600 mr-2 rounded-full"></div>
<div class="text-sm text-gray-700">销售额</div>
</div>
</div>
</div>
<div class="line my-8 relative">
<!-- Tooltip -->
<template x-if="tooltipOpen == true">
<div x-ref="tooltipContainer" class="p-0 m-0 z-10 shadow-lg rounded-lg absolute h-auto block" :style="`bottom: ${tooltipY}px; left: ${tooltipX}px`">
<div class="shadow-xs rounded-lg bg-white p-2">
<div class="flex items-center justify-between text-sm">
<div>销售额:</div>
<div class="font-bold ml-2">
<span x-html="tooltipContent"></span>
</div>
</div>
</div>
</div>
</template>
<!-- Bar Chart -->
<div class="flex -mx-2 items-end mb-2">
<template x-for="data in chartData">
<div class="px-2 w-1/6">
<div :style="`height: ${data}px`" class="transition ease-in duration-200 bg-blue-600 hover:bg-blue-400 relative" @mouseenter="showTooltip($event); tooltipOpen = true" @mouseleave="hideTooltip($event)">
<div x-text="data" class="text-center absolute top-0 left-0 right-0 -mt-6 text-gray-800 text-sm"></div>
</div>
</div>
</template>
</div>
<!-- Labels -->
<div class="border-t border-gray-400 mx-auto" :style="`height: 1px; width: ${ 100 - 1/chartData.length*100 + 3}%`"></div>
<div class="flex -mx-2 items-end">
<template x-for="data in labels">
<div class="px-2 w-1/6">
<div class="bg-red-600 relative">
<div class="text-center absolute top-0 left-0 right-0 h-2 -mt-px bg-gray-400 mx-auto" style="width: 1px"></div>
<div x-text="data" class="text-center absolute top-0 left-0 right-0 mt-3 text-gray-700 text-sm"></div>
</div>
</div>
</template>
</div>
</div>
</div>
</div>
</div>
<script>
function app() {
return {
chartData: [112, 10, 225, 134, 101, 80, 50, 100, 200, 50],
labels: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月'],
tooltipContent: '',
tooltipOpen: false,
tooltipX: 0,
tooltipY: 0,
showTooltip(e) {
console.log(e);
this.tooltipContent = e.target.textContent
this.tooltipX = e.target.offsetLeft - e.target.clientWidth;
this.tooltipY = e.target.clientHeight + e.target.clientWidth;
},
hideTooltip(e) {
this.tooltipContent = '';
this.tooltipOpen = false;
this.tooltipX = 0;
this.tooltipY = 0;
}
}
}
</script>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
<p>适用浏览器:360、FireFox、Chrome、Opera、傲游、搜狗、世界之窗. 不支持Safari、IE8及以下浏览器。</p>
<p>更多源码<a href="http://www.96flw.com" target="_blank">www.96flw.com</a></p>
</div>
</body>
</html>
H5产品月销售额柱状图表.zip
版权申诉
42 浏览量
2023-10-10
23:42:38
上传
评论
收藏 141KB ZIP 举报
码云笔记
- 粉丝: 2w+
- 资源: 5837