index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="dashboard-container column-page-wrap">
  3. <!-- Echarts 图表 -->
  4. <el-row :gutter="40" style="margin-top: 20px">
  5. <el-col :sm="24" :lg="8" class="card-panel__col">
  6. <BarChart id="barChart" height="400px" width="100%" class="chart-container" />
  7. </el-col>
  8. <el-col :sm="24" :lg="8" class="card-panel__col">
  9. <LeChart
  10. class="local_chartWrap"
  11. ref="chartRef"
  12. :loading="chartLoading"
  13. :showChart="showChart"
  14. :option="chartOption"
  15. :height="height"
  16. label_topLeft="label_topLeft"
  17. label_topRight="label_topRight"
  18. label_bottomLeft="label_bottomLeft"
  19. label_bottomRight="label_bottomRight"
  20. />
  21. </el-col>
  22. <el-col :sm="24" :lg="8" class="card-panel__col">
  23. <LeChart :loading="chartLoading2" isInitOption :option="chartOption2" height="400px" />
  24. </el-col>
  25. </el-row>
  26. </div>
  27. </template>
  28. <script setup name="dashboard" lang="ts">
  29. // 组件引用
  30. import BarChart from './components/Chart/BarChart.vue'
  31. // import LeChart from '@/components/Chart.vue'
  32. import { reactive, ref, toRefs } from 'vue'
  33. import * as echarts from 'echarts'
  34. const getChartData = () => ({
  35. title: {
  36. show: true,
  37. text: '业绩总览',
  38. x: 'center',
  39. padding: 15,
  40. textStyle: {
  41. fontSize: 18,
  42. fontStyle: 'normal',
  43. fontWeight: 'bold',
  44. color: '#337ecc'
  45. }
  46. },
  47. grid: {
  48. left: '2%',
  49. right: '2%',
  50. bottom: '10%',
  51. containLabel: true
  52. },
  53. tooltip: {
  54. // show: true,
  55. trigger: 'axis',
  56. axisPointer: {
  57. type: 'cross',
  58. crossStyle: {
  59. color: '#999'
  60. }
  61. }
  62. },
  63. legend: {
  64. x: 'center',
  65. y: 'bottom',
  66. data: ['收入', '毛利润', '收入增长率', '利润增长率']
  67. },
  68. xAxis: [
  69. {
  70. type: 'category',
  71. data: ['上海', '北京', '浙江', '广东', '深圳', '四川', '湖北', '安徽'],
  72. axisPointer: {
  73. type: 'shadow'
  74. }
  75. }
  76. ],
  77. yAxis: [
  78. {
  79. type: 'value',
  80. min: 0,
  81. max: 10000,
  82. interval: 2000,
  83. axisLabel: {
  84. formatter: '{value} '
  85. }
  86. },
  87. {
  88. type: 'value',
  89. min: 0,
  90. max: 100,
  91. interval: 20,
  92. axisLabel: {
  93. formatter: '{value}%'
  94. }
  95. }
  96. ],
  97. series: [
  98. {
  99. name: '收入',
  100. type: 'bar',
  101. data: [8000, 8200, 7000, 6200, 6500, 5500, 4500, 4200, 3800],
  102. barWidth: 20,
  103. itemStyle: {
  104. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  105. { offset: 0, color: '#83bff6' },
  106. { offset: 0.5, color: '#188df0' },
  107. { offset: 1, color: '#188df0' }
  108. ])
  109. }
  110. },
  111. {
  112. name: '毛利润',
  113. type: 'bar',
  114. data: [6700, 6800, 6300, 5213, 4500, 4200, 4200, 3800],
  115. barWidth: 20,
  116. itemStyle: {
  117. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  118. { offset: 0, color: '#25d73c' },
  119. { offset: 0.5, color: '#1bc23d' },
  120. { offset: 1, color: '#179e61' }
  121. ])
  122. }
  123. },
  124. {
  125. name: '收入增长率',
  126. type: 'line',
  127. yAxisIndex: 1,
  128. data: [65, 67, 65, 53, 47, 45, 43, 42, 41],
  129. itemStyle: {
  130. color: '#67C23A'
  131. }
  132. },
  133. {
  134. name: '利润增长率',
  135. type: 'line',
  136. yAxisIndex: 1,
  137. data: [80, 81, 78, 67, 65, 60, 56, 51, 45],
  138. itemStyle: {
  139. color: '#409EFF'
  140. }
  141. }
  142. ]
  143. })
  144. const getChartData2 = () => ({
  145. title: {
  146. show: true,
  147. text: '产品分类总览',
  148. x: 'center',
  149. padding: 15,
  150. textStyle: {
  151. fontSize: 18,
  152. fontStyle: 'normal',
  153. fontWeight: 'bold',
  154. color: '#337ecc'
  155. }
  156. },
  157. grid: {
  158. left: '2%',
  159. right: '2%',
  160. bottom: '10%',
  161. containLabel: true
  162. },
  163. legend: {
  164. top: 'bottom'
  165. },
  166. series: [
  167. {
  168. name: 'Nightingale Chart',
  169. type: 'pie',
  170. radius: [50, 130],
  171. center: ['50%', '50%'],
  172. roseType: 'area',
  173. itemStyle: {
  174. borderRadius: 6,
  175. normal: {
  176. color: function (params: any) {
  177. //自定义颜色
  178. const colorList = ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C']
  179. return colorList[params.dataIndex]
  180. }
  181. }
  182. },
  183. data: [
  184. { value: 26, name: '家用电器' },
  185. { value: 27, name: '户外运动' },
  186. { value: 24, name: '汽车用品' },
  187. { value: 23, name: '手机数码' }
  188. ]
  189. }
  190. ]
  191. })
  192. const chartRef = ref()
  193. window.chartRef = chartRef
  194. const state = reactive({
  195. chartLoading: false,
  196. chartOption: {},
  197. showChart: true,
  198. width: '100%',
  199. height: '600px',
  200. chartLoading2: false,
  201. chartOption2: getChartData2(),
  202. /*chartOption: getChartData()*/
  203. })
  204. const { chartLoading, chartOption, width, height, showChart, chartLoading2, chartOption2 } = toRefs(state)
  205. window.test_showChart = () => (showChart.value = !showChart.value)
  206. window.test_localStyle = (width_ = '100%', height_ = '600px') => {
  207. width.value = width_
  208. height.value = height_
  209. }
  210. // lineChart
  211. new Promise(resolve => {
  212. state.chartLoading = true
  213. setTimeout(() => {
  214. resolve(getChartData())
  215. }, 1000)
  216. }).then((res: any) => {
  217. console.error(res, 'res////////')
  218. state.chartOption = res
  219. state.chartLoading = false
  220. // setTimeout(() => {
  221. // state.chartLoading = false
  222. // }, 50)
  223. })
  224. // pieChart
  225. new Promise(resolve => {
  226. state.chartLoading2 = true
  227. setTimeout(() => {
  228. resolve(getChartData2())
  229. }, 500)
  230. }).then((res: any) => {
  231. console.error(res, 'pieChart res////////')
  232. state.chartOption2 = res
  233. state.chartLoading2 = false
  234. })
  235. </script>
  236. <style lang="scss" scoped>
  237. .dashboard-container {
  238. overflow-y: auto;
  239. padding: 24px;
  240. background-color: rgb(240, 242, 245);
  241. position: relative;
  242. .card-panel__col {
  243. margin-bottom: 12px;
  244. }
  245. .chart-container {
  246. background: #ffffff;
  247. }
  248. }
  249. </style>