chartView.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="dashboard-container">
  3. <el-card shadow="hover" style="height: 600px; width: 100%; position: relative">
  4. <!-- 加载状态 -->
  5. <div v-loading="loading" element-loading-text="数据加载中..."
  6. element-loading-background="rgba(255, 255, 255, 0.8)" style="height: 100%; width: 100%">
  7. <!-- 数据展示区域 -->
  8. <div v-show="!loading" class="chart-container" >
  9. <!-- 第一行:关键指标 -->
  10. <el-row :gutter="20" class="mb-20" >
  11. <el-col :span="8">
  12. <div class="chart-title">节点类型分布</div>
  13. <div ref="nodePieChart" style="height: 250px; width: 500px"></div>
  14. </el-col>
  15. <el-col :span="16">
  16. <div class="chart-title">节点度数分布</div>
  17. <div ref="degreeBarChart" style="height: 250px; width: 950px"></div>
  18. </el-col>
  19. </el-row>
  20. <!-- 第二行:链式分析 -->
  21. <el-row>
  22. <el-col :span="24">
  23. <div class="chart-title">链式结构分析</div>
  24. </el-col>
  25. </el-row>
  26. <el-row :gutter="20" class="mb-20">
  27. <el-col :span="4">
  28. <el-statistic title="总链数" :value="data.chains.num" style="width: 100%; padding-top: 40%; text-align: center;"/>
  29. </el-col>
  30. <el-col :span="4">
  31. <el-statistic title="平均长度" :value="data.chains.averageLength" style="width: 100%; padding-top: 40%; text-align: center;"/>
  32. </el-col>
  33. <el-col :span="16">
  34. <div ref="chainChart" style="width: 950px; height: 250px"></div>
  35. </el-col>
  36. </el-row>
  37. </div>
  38. </div>
  39. </el-card>
  40. </div>
  41. </template>
  42. <script setup>
  43. import { ref, onMounted, nextTick } from 'vue'
  44. import * as echarts from 'echarts'
  45. import { ElLoading } from 'element-plus'
  46. import { getData } from '@/api/axios.js'
  47. const props = defineProps({
  48. result: {
  49. type: Number,
  50. required: true,
  51. }
  52. })
  53. const loading = ref(true)
  54. const data = ref({
  55. sNodesNum: 0,
  56. dNodesNum: 0,
  57. iNodesNum: 0,
  58. sDegree: [],
  59. dDegree: [],
  60. iDegree: [],
  61. chains: {
  62. num: 0,
  63. averageLength: 0,
  64. numByLength: []
  65. }
  66. })
  67. // DOM引用
  68. const nodePieChart = ref(null)
  69. const degreeBarChart = ref(null)
  70. const chainChart = ref(null)
  71. // 图表颜色配置
  72. const colorPalette = [
  73. '#5470c6', '#91cc75', '#fac858',
  74. '#ee6666', '#73c0de', '#3ba272',
  75. '#fc8452', '#9a60b4', '#ea7ccc'
  76. ]
  77. // 获取数据(模拟API调用)
  78. const fetchData = async () => {
  79. try {
  80. // 这里替换为实际的API调用
  81. const response = await getData('/generateGraph', {method: 'chart', result: props.result})
  82. data.value = response.data
  83. } finally {
  84. loading.value = false
  85. nextTick()
  86. initCharts()
  87. }
  88. }
  89. // 初始化图表
  90. const initCharts = () => {
  91. initNodePieChart()
  92. initDegreeChart()
  93. initChainChart()
  94. }
  95. // 节点类型饼图
  96. const initNodePieChart = () => {
  97. const chart = echarts.init(nodePieChart.value)
  98. const option = {
  99. color: colorPalette,
  100. tooltip: { trigger: 'item' },
  101. legend: { top: 'bottom' },
  102. series: [{
  103. type: 'pie',
  104. radius: ['40%', '70%'],
  105. data: [
  106. { value: data.value.sNodesNum, name: 'S节点' },
  107. { value: data.value.dNodesNum, name: 'D节点' },
  108. { value: data.value.iNodesNum, name: 'I节点' }
  109. ],
  110. label: { show: false },
  111. emphasis: {
  112. label: { show: true }
  113. }
  114. }],
  115. }
  116. chart.setOption(option)
  117. }
  118. // 度数分布柱状图
  119. const initDegreeChart = () => {
  120. const chart = echarts.init(degreeBarChart.value)
  121. const option = {
  122. color: colorPalette,
  123. tooltip: { trigger: 'axis' },
  124. xAxis: {
  125. type: 'category',
  126. data: data.value.sDegree.map((_, i) => `度数 ${i}`)
  127. },
  128. yAxis: { type: 'value' },
  129. legend: { data: ['S节点', 'D节点', 'I节点'] },
  130. series: [
  131. { name: 'S节点', type: 'bar', data: data.value.sDegree },
  132. { name: 'D节点', type: 'bar', data: data.value.dDegree },
  133. { name: 'I节点', type: 'bar', data: data.value.iDegree }
  134. ]
  135. }
  136. chart.setOption(option)
  137. }
  138. // 链式结构分析
  139. const initChainChart = () => {
  140. const chart = echarts.init(chainChart.value)
  141. //横坐标,最后一个是长度大于等于5
  142. const xAxisData = data.value.chains.numByLength.map((_, i) => {
  143. if(i == data.value.chains.numByLength.length - 1){
  144. return `长度 ${i + 1} 以上`
  145. }else{
  146. return `长度 ${i + 1}`
  147. }
  148. })
  149. const option = {
  150. color: colorPalette,
  151. tooltip: { trigger: 'axis' },
  152. xAxis: {
  153. type: 'category',
  154. data: xAxisData,
  155. },
  156. yAxis: { type: 'value' },
  157. series: [{
  158. type: 'bar',
  159. data: data.value.chains.numByLength,
  160. itemStyle: { borderRadius: 5 }
  161. }]
  162. }
  163. chart.setOption(option)
  164. }
  165. onMounted(fetchData)
  166. </script>
  167. <style scoped>
  168. .dashboard-container {
  169. padding: 20px;
  170. }
  171. .chart-title {
  172. font-size: 16px;
  173. font-weight: 600;
  174. margin-bottom: 15px;
  175. color: var(--el-text-color-primary);
  176. }
  177. .chain-stats {
  178. display: flex;
  179. gap: 40px;
  180. align-items: center;
  181. margin-bottom: 20px;
  182. width: 100%;
  183. }
  184. .mb-20 {
  185. margin-bottom: 20px;
  186. }
  187. /* 响应式调整 */
  188. @media (max-width: 1200px) {
  189. .chain-stats {
  190. flex-direction: column;
  191. align-items: flex-start;
  192. }
  193. }
  194. </style>