knowledge_graph.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>知识图谱 - 初中化学</title>
  7. <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
  8. <style>
  9. * { margin: 0; padding: 0; box-sizing: border-box; }
  10. body { font-family: 'Segoe UI', sans-serif; background: #f5f7fa; }
  11. .sidebar {
  12. width: 220px;
  13. position: fixed;
  14. left: 0;
  15. top: 0;
  16. bottom: 0;
  17. background: #2c3e50;
  18. color: #ecf0f1;
  19. padding: 20px 0;
  20. }
  21. .sidebar a { color: inherit; text-decoration: none; display: block; padding: 10px 20px; }
  22. .sidebar a:hover { background: #34495e; }
  23. .main { margin-left: 220px; padding: 20px; }
  24. .chart-wrap { background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); height: 600px; }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="sidebar">
  29. <a href="/dashboard">🏠 首页</a>
  30. <a href="/knowledge_qa">💬 知识点询问</a>
  31. <a href="/knowledge_graph">🔗 知识图谱</a>
  32. <a href="/daily_training">📚 每日训练</a>
  33. <a href="/analysis">📊 学情分析</a>
  34. </div>
  35. <div class="main">
  36. <h2 style="margin-bottom: 16px;">初中化学知识图谱</h2>
  37. <div class="chart-wrap" id="graphChart" data-graph='{{ graph_data | tojson | safe }}'></div>
  38. </div>
  39. <script>
  40. const container = document.getElementById('graphChart');
  41. const graphData = JSON.parse(container.dataset.graph || '{"nodes":[],"links":[]}');
  42. const chart = echarts.init(container);
  43. const option = {
  44. title: { text: '三元组关系图', left: 'center' },
  45. tooltip: { formatter: d => d.data.source + ' - ' + d.data.target },
  46. series: [{
  47. type: 'graph',
  48. layout: 'force',
  49. data: graphData.nodes.map(n => ({ name: n.name })),
  50. links: graphData.links.map(l => ({ source: l.source, target: l.target, value: l.value })),
  51. label: { show: true, position: 'right' },
  52. force: { repulsion: 500, edgeLength: 150 }
  53. }]
  54. };
  55. chart.setOption(option);
  56. window.addEventListener('resize', () => chart.resize());
  57. </script>
  58. </body>
  59. </html>