当前位置: 首页 > ds >正文

根据输入的数据渲染柱形图

背景:根据不同季度的销售额,生成对应的柱形图,直观的看出差异

效果:

代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>* {margin: 0;padding: 0;}body {background-color: #0c143d;}.box {display: flex;justify-content: space-around;align-items: flex-end;width: 800px;min-height: 300px;border-left: 1px solid #4b578f;border-bottom: 1px solid #4b578f;margin: 0 auto;padding-top: 50px;text-align: center;color: #9799ab;}.box>div {position: relative;display: flex;flex-direction: column;justify-content: space-between;width: 40px;height: 0;background: linear-gradient(#3c99ff, #4489d0, #2283e4);cursor: pointer;border-radius: 8px 8px 0 0;transition: all .2s;}.box>div:hover {animation: bg .5s alternate infinite;}@keyframes bg {to {box-shadow: 0 5px 29px rgb(53 111 226 / 88%);background: linear-gradient(#3c99ff, #68aff6, #2283e4);}}.box>div::after {content: '';position: absolute;bottom: 0;left: 50%;width: 2px;height: 10px;background-color: #4b578f;transform: translate(-50%, 100%);}.box div span {width: 60px;margin: -30px 0 -5px -6px;}.box div h4 {width: 70px;margin: 0 0 -35px -10px;}.title {margin-top: 50px;text-align: center;color: #9799ab;}</style>
</head><body><h3 class="title">2099年季度销售数额(单位万)</h3><!-- <div class="box"><div style="height: 123px;" title="第1季度-123万"><span>123万</span><h4>第1季度</h4></div><div style="height: 156px;" title="第2季度-156万"><span>156万</span><h4>第2季度</h4></div><div style="height: 120px;" title="第3季度-120万"><span>120万</span><h4>第3季度</h4></div><div style="height: 210px;" title="第4季度-210万"><span>210万</span><h4>第4季度</h4></div></div> --><script>// 功能1: 用户输入4次,并且把数据存放到数组里面// 1.1 声明一个空的数组let arr = []// 1.2 利用循环的形式让用户输入4次,并且把数据追加给数组for (let i = 1; i <= 4; i++) {let num = +prompt(`请您输入第${i}季度的销售额`)arr.push(num)}console.log(arr)// 功能2:根据数组生成柱形图// 2.1 声明一个空的字符串 strlet str = ''// 2.2 利用循环拼接字符串,生成多个柱子for (let i = 0; i < arr.length; i++) {str += `<div style="height: ${arr[i]}px;" title="第${i + 1}季度-${arr[i]}万"><span>${arr[i]}万</span><h4>第${i + 1}季度</h4></div>`}console.log(str)// 2.3 把生成的柱子放到box盒子里面进行渲染document.write(`<div class="box">${str}</div> `)</script>
</body></html>

http://www.xdnf.cn/news/6001.html

相关文章:

  • 分布式异步强化学习框架训练32B大模型:INTELLECT-2
  • React Native 与 Expo
  • 迅龙3号基于兆讯MH22D3适配CST328多点触摸驱动开发笔记
  • 分别在windows和linux上使用curl,有啥区别?
  • INT202 Complexity of Algroithms 算法的复杂度 Pt.7 NP-Completeness NP完全性
  • JuiceFS v1.3-beta1:新增 Python SDK,特定场景性能 3 倍于 FUSE
  • XA协议和Tcc
  • Vue3+Vite单页面应用(SPA)改造为多页面应用(MPA)
  • 内存泄漏与OOM崩溃根治方案:JVM与原生内存池差异化排查手册
  • 2025.05.11拼多多机考真题算法岗-第三题
  • 当java进程内存使用超过jvm设置大小会发生什么?
  • 数据库原理实验:视图与索引
  • 游戏引擎学习第276天:调整身体动画
  • 【计算机网络】3数据链路层②
  • STM32 __main汇编分析
  • 基于 mathematical-expression 的动态数学方程求解器实现
  • 如何使用C51的Timer0实现定时功能
  • DeepBook 与 CEX 的不同
  • HDFS的客户端操作(2)文件上传
  • 重庆医科大学附属第二医院外科楼外挡墙自动化监测
  • 鸿蒙5.0项目开发——鸿蒙天气项目的实现(介绍)
  • OJ判题系统第6期之判题逻辑开发——设计思路、实现步骤、代码实现(策略模式)
  • 目标检测任务 - 数据增强
  • Linux文件编程——标准库函数(fopen等)和系统调用函数(open等)的区别
  • 无锡哲讯科技:引领芯片封装SAP系统的智能化革命
  • Flannel Host-gw模式的优缺点
  • Leetcode 3544. Subtree Inversion Sum
  • 深入学习 Java 泛型实现方式:擦除法!
  • 43、Server.UrlEncode、HttpUtility.UrlDecode的区别?
  • 物理:篮球为什么能被拍起来?