knowledgePointAnalysis.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>知识点学习情况分析</title>
  7. <!-- 引入Chart.js -->
  8. <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. body {
  16. font-family: 'Microsoft YaHei', Arial, sans-serif;
  17. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  18. min-height: 100vh;
  19. padding: 20px;
  20. }
  21. .container {
  22. max-width: 1400px;
  23. margin: 0 auto;
  24. background: white;
  25. border-radius: 15px;
  26. box-shadow: 0 20px 40px rgba(0,0,0,0.1);
  27. overflow: hidden;
  28. }
  29. header {
  30. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  31. color: white;
  32. padding: 20px;
  33. text-align: center;
  34. }
  35. h1 {
  36. font-size: 28px;
  37. margin-bottom: 10px;
  38. }
  39. .subtitle {
  40. font-size: 16px;
  41. opacity: 0.9;
  42. }
  43. .content {
  44. display: flex;
  45. //height : 950px;
  46. //height: calc(100vh - 120px);
  47. }
  48. #chartContainer {
  49. flex: 1;
  50. padding: 30px;
  51. border-right: 1px solid #eee;
  52. }
  53. #listContainer {
  54. flex: 1;
  55. padding: 30px;
  56. display: flex;
  57. flex-direction: column;
  58. }
  59. .chart-title {
  60. font-size: 20px;
  61. color: #333;
  62. margin-bottom: 20px;
  63. text-align: center;
  64. }
  65. .list-title {
  66. font-size: 20px;
  67. color: #333;
  68. margin-bottom: 20px;
  69. text-align: center;
  70. }
  71. /* 修复柱形图容器,避免变形 */
  72. .chart-wrapper {
  73. position: relative;
  74. width: 100%;
  75. height: 400px;
  76. }
  77. canvas {
  78. width: 100% !important;
  79. height: 100% !important;
  80. max-width: 100%;
  81. }
  82. table {
  83. width: 100%;
  84. border-collapse: collapse;
  85. box-shadow: 0 5px 15px rgba(0,0,0,0.08);
  86. border-radius: 10px;
  87. overflow: hidden;
  88. }
  89. th {
  90. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  91. color: white;
  92. text-align: left;
  93. padding: 15px;
  94. font-weight: 600;
  95. font-size: 14px;
  96. text-transform: uppercase;
  97. letter-spacing: 0.5px;
  98. }
  99. td {
  100. padding: 12px 15px;
  101. border-bottom: 1px solid #eee;
  102. color: #555;
  103. }
  104. tr:hover {
  105. background-color: #f8f9ff;
  106. transform: translateY(-1px);
  107. transition: all 0.3s ease;
  108. }
  109. tbody tr:last-child td {
  110. border-bottom: none;
  111. }
  112. .no-data {
  113. text-align: center;
  114. padding: 40px;
  115. color: #999;
  116. font-style: italic;
  117. }
  118. .chartjs-tooltip {
  119. background: rgba(0, 0, 0, 0.8) !important;
  120. border: none !important;
  121. border-radius: 8px !important;
  122. padding: 10px !important;
  123. color: white !important;
  124. font-size: 14px !important;
  125. }
  126. .selected-knowledge {
  127. background: #f0f8ff;
  128. padding: 15px;
  129. border-radius: 10px;
  130. margin-bottom: 20px;
  131. text-align: center;
  132. font-weight: 600;
  133. color: #4facfe;
  134. border: 2px dashed #4facfe;
  135. }
  136. /* 分页样式 */
  137. .pagination {
  138. display: flex;
  139. justify-content: center;
  140. margin-top: 20px;
  141. gap: 5px;
  142. }
  143. .pagination button {
  144. background: white;
  145. border: 1px solid #ddd;
  146. color: #333;
  147. padding: 8px 12px;
  148. cursor: pointer;
  149. border-radius: 4px;
  150. font-size: 14px;
  151. transition: all 0.3s ease;
  152. }
  153. .pagination button:hover {
  154. background: #f0f0f0;
  155. border-color: #999;
  156. }
  157. .pagination button.active {
  158. background: #4facfe;
  159. color: white;
  160. border-color: #4facfe;
  161. }
  162. .pagination button:disabled {
  163. background: #f5f5f5;
  164. color: #ccc;
  165. cursor: not-allowed;
  166. }
  167. .pagination-info {
  168. text-align: center;
  169. margin-top: 10px;
  170. color: #666;
  171. font-size: 14px;
  172. }
  173. @media (max-width: 768px) {
  174. .content {
  175. flex-direction: column;
  176. }
  177. #chartContainer {
  178. border-right: none;
  179. border-bottom: 1px solid #eee;
  180. }
  181. #listContainer {
  182. height: 400px;
  183. }
  184. .pagination button {
  185. padding: 6px 10px;
  186. font-size: 12px;
  187. }
  188. }
  189. </style>
  190. </head>
  191. <body>
  192. <div class="container">
  193. <header>
  194. <h1>知识点学习情况分析</h1>
  195. <div class="subtitle">实时监控学员学习进度与参与情况</div>
  196. </header>
  197. <div class="content">
  198. <!-- 左侧柱形图 -->
  199. <div id="chartContainer">
  200. <div class="chart-title">各知识点学习人数统计</div>
  201. <div class="chart-wrapper">
  202. <canvas id="myChart"></canvas>
  203. </div>
  204. </div>
  205. <!-- 右侧列表 -->
  206. <div id="listContainer">
  207. <div class="list-title">学习人员名单</div>
  208. <div id="selectedKnowledge" class="selected-knowledge">
  209. 请选择左侧知识点查看学习人员
  210. </div>
  211. <div style="flex: 1; overflow-y: auto;">
  212. <table id="studentTable">
  213. <thead>
  214. <tr>
  215. <th>专业</th>
  216. <th>班级</th>
  217. <th>学号</th>
  218. <th>姓名</th>
  219. </tr>
  220. </thead>
  221. <tbody id="studentList">
  222. <tr><td colspan="4" class="no-data">暂无数据</td></tr>
  223. </tbody>
  224. </table>
  225. </div>
  226. <!-- 分页控件 -->
  227. <div class="pagination-container">
  228. <div class="pagination" id="pagination">
  229. <!-- 分页按钮将通过JavaScript动态生成 -->
  230. </div>
  231. <div class="pagination-info" id="paginationInfo">
  232. <!-- 分页信息将通过JavaScript动态生成 -->
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. <script>
  239. // 示例数据
  240. const knowledgeData = {
  241. labels: ["电传操纵系统", "飞行控制律", "传感器技术", "故障诊断", "人机交互"],
  242. datasets: [{
  243. label: '学习人数',
  244. data: [32, 25, 41, 18, 29],
  245. backgroundColor: [
  246. 'rgba(255, 99, 132, 0.8)',
  247. 'rgba(54, 162, 235, 0.8)',
  248. 'rgba(255, 206, 86, 0.8)',
  249. 'rgba(75, 192, 192, 0.8)',
  250. 'rgba(153, 102, 255, 0.8)'
  251. ],
  252. borderColor: [
  253. 'rgba(255, 99, 132, 1)',
  254. 'rgba(54, 162, 235, 1)',
  255. 'rgba(255, 206, 86, 1)',
  256. 'rgba(75, 192, 192, 1)',
  257. 'rgba(153, 102, 255, 1)'
  258. ],
  259. borderWidth: 2,
  260. borderRadius: 8,
  261. borderSkipped: false
  262. }]
  263. };
  264. // 学员数据
  265. const studentData = [
  266. // 电传操纵系统
  267. [
  268. { major: "航空航天工程", class: "飞控1班", studentId: "2023001", name: "张三" },
  269. { major: "航空航天工程", class: "飞控1班", studentId: "2023002", name: "李四" },
  270. { major: "航空航天工程", class: "飞控2班", studentId: "2023003", name: "王五" },
  271. { major: "航空航天工程", class: "飞控2班", studentId: "2023004", name: "赵六" },
  272. { major: "航空航天工程", class: "飞控3班", studentId: "2023005", name: "钱七" },
  273. { major: "航空航天工程", class: "飞控3班", studentId: "2023006", name: "孙八" },
  274. { major: "航空航天工程", class: "飞控1班", studentId: "2023007", name: "周九" },
  275. { major: "航空航天工程", class: "飞控1班", studentId: "2023008", name: "吴十" },
  276. { major: "航空航天工程", class: "飞控1班", studentId: "2023009", name: "郑一" },
  277. { major: "航空航天工程", class: "飞控2班", studentId: "2023010", name: "王二" },
  278. { major: "航空航天工程", class: "飞控2班", studentId: "2023011", name: "冯三" },
  279. { major: "航空航天工程", class: "飞控3班", studentId: "2023012", name: "陈四" },
  280. { major: "航空航天工程", class: "飞控3班", studentId: "2023013", name: "褚五" },
  281. { major: "航空航天工程", class: "飞控1班", studentId: "2023014", name: "卫六" },
  282. { major: "航空航天工程", class: "飞控1班", studentId: "2023015", name: "蒋七" },
  283. { major: "航空航天工程", class: "飞控2班", studentId: "2023016", name: "沈八" },
  284. { major: "航空航天工程", class: "飞控2班", studentId: "2023017", name: "韩九" },
  285. { major: "航空航天工程", class: "飞控3班", studentId: "2023018", name: "杨十" },
  286. { major: "航空航天工程", class: "飞控3班", studentId: "2023019", name: "朱一" },
  287. { major: "航空航天工程", class: "飞控1班", studentId: "2023020", name: "秦二" },
  288. { major: "航空航天工程", class: "飞控1班", studentId: "2023021", name: "尤三" },
  289. { major: "航空航天工程", class: "飞控2班", studentId: "2023022", name: "许四" },
  290. { major: "航空航天工程", class: "飞控2班", studentId: "2023023", name: "何五" },
  291. { major: "航空航天工程", class: "飞控3班", studentId: "2023024", name: "吕六" },
  292. { major: "航空航天工程", class: "飞控3班", studentId: "2023025", name: "施七" },
  293. { major: "航空航天工程", class: "飞控1班", studentId: "2023026", name: "张八" },
  294. { major: "航空航天工程", class: "飞控1班", studentId: "2023027", name: "孔九" },
  295. { major: "航空航天工程", class: "飞控2班", studentId: "2023028", name: "曹十" },
  296. { major: "航空航天工程", class: "飞控2班", studentId: "2023029", name: "严一" },
  297. { major: "航空航天工程", class: "飞控3班", studentId: "2023030", name: "华二" },
  298. { major: "航空航天工程", class: "飞控3班", studentId: "2023031", name: "金三" },
  299. { major: "航空航天工程", class: "飞控1班", studentId: "2023032", name: "魏四" }
  300. ],
  301. // 飞行控制律
  302. [
  303. { major: "航空航天工程", class: "飞控1班", studentId: "2023033", name: "郑一" },
  304. { major: "航空航天工程", class: "飞控2班", studentId: "2023034", name: "王二" },
  305. { major: "航空航天工程", class: "飞控2班", studentId: "2023035", name: "冯三" },
  306. { major: "航空航天工程", class: "飞控3班", studentId: "2023036", name: "陈四" },
  307. { major: "航空航天工程", class: "飞控3班", studentId: "2023037", name: "褚五" },
  308. { major: "航空航天工程", class: "飞控1班", studentId: "2023038", name: "卫六" },
  309. { major: "航空航天工程", class: "飞控1班", studentId: "2023039", name: "蒋七" },
  310. { major: "航空航天工程", class: "飞控2班", studentId: "2023040", name: "沈八" },
  311. { major: "航空航天工程", class: "飞控2班", studentId: "2023041", name: "韩九" },
  312. { major: "航空航天工程", class: "飞控3班", studentId: "2023042", name: "杨十" },
  313. { major: "航空航天工程", class: "飞控3班", studentId: "2023043", name: "朱一" },
  314. { major: "航空航天工程", class: "飞控1班", studentId: "2023044", name: "秦二" },
  315. { major: "航空航天工程", class: "飞控1班", studentId: "2023045", name: "尤三" },
  316. { major: "航空航天工程", class: "飞控2班", studentId: "2023046", name: "许四" },
  317. { major: "航空航天工程", class: "飞控2班", studentId: "2023047", name: "何五" },
  318. { major: "航空航天工程", class: "飞控3班", studentId: "2023048", name: "吕六" },
  319. { major: "航空航天工程", class: "飞控3班", studentId: "2023049", name: "施七" },
  320. { major: "航空航天工程", class: "飞控1班", studentId: "2023050", name: "张八" },
  321. { major: "航空航天工程", class: "飞控1班", studentId: "2023051", name: "孔九" },
  322. { major: "航空航天工程", class: "飞控2班", studentId: "2023052", name: "曹十" },
  323. { major: "航空航天工程", class: "飞控2班", studentId: "2023053", name: "严一" },
  324. { major: "航空航天工程", class: "飞控3班", studentId: "2023054", name: "华二" },
  325. { major: "航空航天工程", class: "飞控3班", studentId: "2023055", name: "金三" },
  326. { major: "航空航天工程", class: "飞控1班", studentId: "2023056", name: "魏四" }
  327. ],
  328. // 传感器技术
  329. [
  330. { major: "航空航天工程", class: "飞控1班", studentId: "2023057", name: "蒋七" },
  331. { major: "航空航天工程", class: "飞控2班", studentId: "2023058", name: "沈八" },
  332. { major: "航空航天工程", class: "飞控2班", studentId: "2023059", name: "韩九" },
  333. { major: "航空航天工程", class: "飞控3班", studentId: "2023060", name: "杨十" },
  334. { major: "航空航天工程", class: "飞控3班", studentId: "2023061", name: "朱一" },
  335. { major: "航空航天工程", class: "飞控1班", studentId: "2023062", name: "秦二" },
  336. { major: "航空航天工程", class: "飞控1班", studentId: "2023063", name: "尤三" },
  337. { major: "航空航天工程", class: "飞控2班", studentId: "2023064", name: "许四" },
  338. { major: "航空航天工程", class: "飞控2班", studentId: "2023065", name: "何五" },
  339. { major: "航空航天工程", class: "飞控3班", studentId: "2023066", name: "吕六" },
  340. { major: "航空航天工程", class: "飞控3班", studentId: "2023067", name: "施七" },
  341. { major: "航空航天工程", class: "飞控1班", studentId: "2023068", name: "张八" },
  342. { major: "航空航天工程", class: "飞控1班", studentId: "2023069", name: "孔九" },
  343. { major: "航空航天工程", class: "飞控2班", studentId: "2023070", name: "曹十" },
  344. { major: "航空航天工程", class: "飞控2班", studentId: "2023071", name: "严一" },
  345. { major: "航空航天工程", class: "飞控3班", studentId: "2023072", name: "华二" },
  346. { major: "航空航天工程", class: "飞控3班", studentId: "2023073", name: "金三" },
  347. { major: "航空航天工程", class: "飞控1班", studentId: "2023074", name: "魏四" },
  348. { major: "航空航天工程", class: "飞控1班", studentId: "2023075", name: "张三" },
  349. { major: "航空航天工程", class: "飞控2班", studentId: "2023076", name: "李四" },
  350. { major: "航空航天工程", class: "飞控2班", studentId: "2023077", name: "王五" },
  351. { major: "航空航天工程", class: "飞控3班", studentId: "2023078", name: "赵六" },
  352. { major: "航空航天工程", class: "飞控3班", studentId: "2023079", name: "钱七" },
  353. { major: "航空航天工程", class: "飞控1班", studentId: "2023080", name: "孙八" },
  354. { major: "航空航天工程", class: "飞控1班", studentId: "2023081", name: "周九" },
  355. { major: "航空航天工程", class: "飞控2班", studentId: "2023082", name: "吴十" },
  356. { major: "航空航天工程", class: "飞控2班", studentId: "2023083", name: "郑一" },
  357. { major: "航空航天工程", class: "飞控3班", studentId: "2023084", name: "王二" },
  358. { major: "航空航天工程", class: "飞控3班", studentId: "2023085", name: "冯三" }
  359. ],
  360. // 故障诊断
  361. [
  362. { major: "航空航天工程", class: "飞控2班", studentId: "2023086", name: "尤三" },
  363. { major: "航空航天工程", class: "飞控3班", studentId: "2023087", name: "许四" },
  364. { major: "航空航天工程", class: "飞控3班", studentId: "2023088", name: "何五" },
  365. { major: "航空航天工程", class: "飞控1班", studentId: "2023089", name: "吕六" },
  366. { major: "航空航天工程", class: "飞控1班", studentId: "2023090", name: "施七" },
  367. { major: "航空航天工程", class: "飞控2班", studentId: "2023091", name: "张八" },
  368. { major: "航空航天工程", class: "飞控2班", studentId: "2023092", name: "孔九" },
  369. { major: "航空航天工程", class: "飞控3班", studentId: "2023093", name: "曹十" },
  370. { major: "航空航天工程", class: "飞控3班", studentId: "2023094", name: "严一" },
  371. { major: "航空航天工程", class: "飞控1班", studentId: "2023095", name: "华二" },
  372. { major: "航空航天工程", class: "飞控1班", studentId: "2023096", name: "金三" },
  373. { major: "航空航天工程", class: "飞控2班", studentId: "2023097", name: "魏四" },
  374. { major: "航空航天工程", class: "飞控2班", studentId: "2023098", name: "张三" },
  375. { major: "航空航天工程", class: "飞控3班", studentId: "2023099", name: "李四" },
  376. { major: "航空航天工程", class: "飞控3班", studentId: "2023100", name: "王五" },
  377. { major: "航空航天工程", class: "飞控1班", studentId: "2023101", name: "赵六" },
  378. { major: "航空航天工程", class: "飞控1班", studentId: "2023102", name: "钱七" },
  379. { major: "航空航天工程", class: "飞控2班", studentId: "2023103", name: "孙八" }
  380. ],
  381. // 人机交互
  382. [
  383. { major: "航空航天工程", class: "飞控1班", studentId: "2023104", name: "施七" },
  384. { major: "航空航天工程", class: "飞控2班", studentId: "2023105", name: "张八" },
  385. { major: "航空航天工程", class: "飞控2班", studentId: "2023106", name: "孔九" },
  386. { major: "航空航天工程", class: "飞控3班", studentId: "2023107", name: "曹十" },
  387. { major: "航空航天工程", class: "飞控3班", studentId: "2023108", name: "严一" },
  388. { major: "航空航天工程", class: "飞控1班", studentId: "2023109", name: "华二" },
  389. { major: "航空航天工程", class: "飞控1班", studentId: "2023110", name: "金三" },
  390. { major: "航空航天工程", class: "飞控2班", studentId: "2023111", name: "魏四" },
  391. { major: "航空航天工程", class: "飞控2班", studentId: "2023112", name: "张三" },
  392. { major: "航空航天工程", class: "飞控3班", studentId: "2023113", name: "李四" },
  393. { major: "航空航天工程", class: "飞控3班", studentId: "2023114", name: "王五" },
  394. { major: "航空航天工程", class: "飞控1班", studentId: "2023115", name: "赵六" },
  395. { major: "航空航天工程", class: "飞控1班", studentId: "2023116", name: "钱七" },
  396. { major: "航空航天工程", class: "飞控2班", studentId: "2023117", name: "孙八" },
  397. { major: "航空航天工程", class: "飞控2班", studentId: "2023118", name: "周九" },
  398. { major: "航空航天工程", class: "飞控3班", studentId: "2023119", name: "吴十" },
  399. { major: "航空航天工程", class: "飞控3班", studentId: "2023120", name: "郑一" },
  400. { major: "航空航天工程", class: "飞控1班", studentId: "2023121", name: "王二" },
  401. { major: "航空航天工程", class: "飞控1班", studentId: "2023122", name: "冯三" },
  402. { major: "航空航天工程", class: "飞控2班", studentId: "2023123", name: "陈四" },
  403. { major: "航空航天工程", class: "飞控2班", studentId: "2023124", name: "褚五" },
  404. { major: "航空航天工程", class: "飞控3班", studentId: "2023125", name: "卫六" },
  405. { major: "航空航天工程", class: "飞控3班", studentId: "2023126", name: "蒋七" },
  406. { major: "航空航天工程", class: "飞控1班", studentId: "2023127", name: "沈八" },
  407. { major: "航空航天工程", class: "飞控1班", studentId: "2023128", name: "韩九" },
  408. { major: "航空航天工程", class: "飞控2班", studentId: "2023129", name: "杨十" },
  409. { major: "航空航天工程", class: "飞控2班", studentId: "2023130", name: "朱一" },
  410. { major: "航空航天工程", class: "飞控3班", studentId: "2023131", name: "秦二" },
  411. { major: "航空航天工程", class: "飞控3班", studentId: "2023132", name: "尤三" }
  412. ]
  413. ];
  414. // 每页显示的项目数量
  415. const ITEMS_PER_PAGE = 10;
  416. // 当前分页信息
  417. let currentPage = 1;
  418. let totalPages = 1;
  419. let currentDataIndex = 0;
  420. // 创建柱形图
  421. const ctx = document.getElementById('myChart').getContext('2d');
  422. const myChart = new Chart(ctx, {
  423. type: 'bar',
  424. data: knowledgeData,
  425. options: {
  426. responsive: true,
  427. maintainAspectRatio: false,
  428. plugins: {
  429. legend: {
  430. display: false
  431. },
  432. tooltip: {
  433. backgroundColor: 'rgba(0, 0, 0, 0.8)',
  434. titleColor: 'white',
  435. bodyColor: 'white',
  436. borderColor: 'rgba(255, 255, 255, 0.3)',
  437. borderWidth: 1,
  438. cornerRadius: 8,
  439. displayColors: false,
  440. callbacks: {
  441. label: function(context) {
  442. return `学习人数: ${context.parsed.y}人`;
  443. }
  444. }
  445. }
  446. },
  447. scales: {
  448. y: {
  449. beginAtZero: true,
  450. ticks: {
  451. stepSize: 5,
  452. color: '#666',
  453. font: {
  454. size: 12,
  455. family: 'Microsoft YaHei, Arial, sans-serif'
  456. }
  457. },
  458. grid: {
  459. color: 'rgba(0, 0, 0, 0.1)'
  460. }
  461. },
  462. x: {
  463. ticks: {
  464. color: '#666',
  465. font: {
  466. size: 12,
  467. family: 'Microsoft YaHei, Arial, sans-serif'
  468. },
  469. maxRotation: 45,
  470. minRotation: 45
  471. },
  472. grid: {
  473. display: false
  474. }
  475. }
  476. },
  477. onClick: (event, elements) => {
  478. if (elements.length > 0) {
  479. const index = elements[0].index;
  480. currentDataIndex = index;
  481. currentPage = 1; // 重置为第一页
  482. updateStudentList(index, 1);
  483. // 更新选中知识点显示
  484. document.getElementById('selectedKnowledge').innerHTML =
  485. `<strong>当前查看:</strong> ${knowledgeData.labels[index]}
  486. <span style="color: #666; font-weight: normal;">(${knowledgeData.datasets[0].data[index]}人学习)</span>`;
  487. }
  488. },
  489. interaction: {
  490. intersect: false,
  491. mode: 'index'
  492. }
  493. }
  494. });
  495. // 更新右侧列表(带分页)
  496. function updateStudentList(index, page = 1) {
  497. const listContainer = document.getElementById('studentList');
  498. const students = studentData[index];
  499. const paginationContainer = document.getElementById('pagination');
  500. const paginationInfo = document.getElementById('paginationInfo');
  501. if (students && students.length > 0) {
  502. // 计算分页
  503. totalPages = Math.ceil(students.length / ITEMS_PER_PAGE);
  504. currentPage = page;
  505. // 计算当前页的数据
  506. const startIndex = (page - 1) * ITEMS_PER_PAGE;
  507. const endIndex = Math.min(startIndex + ITEMS_PER_PAGE, students.length);
  508. const currentPageData = students.slice(startIndex, endIndex);
  509. // 清空列表并添加当前页数据
  510. listContainer.innerHTML = '';
  511. currentPageData.forEach(student => {
  512. const tr = document.createElement('tr');
  513. tr.innerHTML = `
  514. <td>${student.major}</td>
  515. <td>${student.class}</td>
  516. <td>${student.studentId}</td>
  517. <td>${student.name}</td>
  518. `;
  519. listContainer.appendChild(tr);
  520. });
  521. // 更新分页信息
  522. paginationInfo.textContent = `共 ${students.length} 条记录,第 ${page} 页,共 ${totalPages} 页`;
  523. // 生成分页按钮
  524. generatePaginationButtons();
  525. } else {
  526. listContainer.innerHTML = '<tr><td colspan="4" class="no-data">暂无学习人员</td></tr>';
  527. paginationContainer.innerHTML = '';
  528. paginationInfo.textContent = '';
  529. }
  530. }
  531. // 生成分页按钮
  532. function generatePaginationButtons() {
  533. const paginationContainer = document.getElementById('pagination');
  534. paginationContainer.innerHTML = '';
  535. // 上一页按钮
  536. const prevButton = document.createElement('button');
  537. prevButton.innerHTML = '&laquo;';
  538. prevButton.disabled = currentPage === 1;
  539. prevButton.addEventListener('click', () => {
  540. if (currentPage > 1) {
  541. updateStudentList(currentDataIndex, currentPage - 1);
  542. }
  543. });
  544. paginationContainer.appendChild(prevButton);
  545. // 页码按钮(最多显示5个页码)
  546. const maxVisiblePages = 5;
  547. let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
  548. let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
  549. // 如果接近末尾,调整起始页
  550. if (endPage - startPage + 1 < maxVisiblePages) {
  551. startPage = Math.max(1, endPage - maxVisiblePages + 1);
  552. }
  553. for (let i = startPage; i <= endPage; i++) {
  554. const pageButton = document.createElement('button');
  555. pageButton.textContent = i;
  556. pageButton.classList.toggle('active', i === currentPage);
  557. pageButton.addEventListener('click', () => {
  558. updateStudentList(currentDataIndex, i);
  559. });
  560. paginationContainer.appendChild(pageButton);
  561. }
  562. // 下一页按钮
  563. const nextButton = document.createElement('button');
  564. nextButton.innerHTML = '&raquo;';
  565. nextButton.disabled = currentPage === totalPages;
  566. nextButton.addEventListener('click', () => {
  567. if (currentPage < totalPages) {
  568. updateStudentList(currentDataIndex, currentPage + 1);
  569. }
  570. });
  571. paginationContainer.appendChild(nextButton);
  572. }
  573. // 页面加载完成后,默认显示第一个知识点的人员列表
  574. window.addEventListener('load', function() {
  575. // 等待Chart.js完全渲染完成
  576. setTimeout(() => {
  577. // 默认选择第一个知识点
  578. const firstIndex = 0;
  579. currentDataIndex = firstIndex;
  580. currentPage = 1;
  581. updateStudentList(firstIndex, 1);
  582. // 更新选中知识点显示
  583. document.getElementById('selectedKnowledge').innerHTML =
  584. `<strong>当前查看:</strong> ${knowledgeData.labels[firstIndex]}
  585. <span style="color: #666; font-weight: normal;">(${knowledgeData.datasets[0].data[firstIndex]}人学习)</span>`;
  586. }, 100);
  587. });
  588. </script>
  589. </body>
  590. </html>