• vue柱状图+table表格


    1. <template>
    2. <el-container class="train-plan-index">
    3. <el-header>
    4. <el-row>
    5. <el-col :span="24">
    6. <el-form :inline="true" :model="form" :rules="rules" class="demo-form-inline" ref="form">
    7. <el-form-item label="统计类型" prop="timeSpan">
    8. <el-select v-model="form.timeSpan">
    9. <el-option v-for="item in timeSpanList" :key="item.value" :label="item.label" :value="item.value">el-option>
    10. el-select>
    11. el-form-item>
    12. <span v-if="form.timeSpan == 'year'" class="year-span">
    13. <el-form-item label="时间" prop="yearStart" style="width:50px">
    14. <el-date-picker v-model="form.yearStart" type="year" placeholder="选择年" value-format="yyyy" :clearable="false"> el-date-picker>
    15. el-form-item>
    16. <span style="margin-right: 10px">-span>
    17. <el-form-item prop="yearEnd">
    18. <el-date-picker v-model="form.yearEnd" type="year" placeholder="选择年" value-format="yyyy" :clearable="false"> el-date-picker>
    19. el-form-item>
    20. span>
    21. <el-form-item label="时间" prop="time" v-if="form.timeSpan == 'month'">
    22. <el-date-picker v-model="form.time" type="monthrange" range-separator="—" start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM" :clearable="false">
    23. el-date-picker>
    24. el-form-item>
    25. <el-form-item>
    26. <el-button type="primary" @click="onQuery">查询el-button>
    27. <el-button @click="resetForm">重置el-button>
    28. el-form-item>
    29. el-form>
    30. el-col>
    31. el-row>
    32. el-header>
    33. <el-main class="stat-main">
    34. <div class="chart-div">
    35. <div class="stat-text-div">
    36. <el-form label-width="125px" class="demo-form">
    37. <el-row>
    38. <el-col :span="8">
    39. <el-form-item label="总培训次数">
    40. <el-input v-model="sumTrainCount" :disabled="true">el-input>
    41. el-form-item>
    42. el-col>
    43. <el-col :span="8" :disable="true">
    44. <el-form-item label="总培训时长">
    45. <el-input v-model="sumTrainTime" :disabled="true">el-input>
    46. el-form-item>
    47. el-col>
    48. el-row>
    49. el-form>
    50. div>
    51. <div id="trainStatCharts" class="stat-chart-div">div>
    52. div>
    53. <div class="table-div">
    54. <el-table :data="tableData" border style="width: 100%" stripe height="calc(100% - 40px)" :default-sort="{ prop: 'saveTime', order: 'descending' }">
    55. <el-table-column type="index" label="序号" align="center" width="60" :index="(index) => this.$common.pageIndexMethod(index, form.pageIndex, form.pageSize)"> el-table-column>
    56. <el-table-column prop="trainId" label="培训编号" align="center" width="150"> el-table-column>
    57. <el-table-column prop="project" label="培训项目" align="center" width="150"> el-table-column>
    58. <el-table-column prop="applyCompany" label="申请单位" align="center" width="100"> el-table-column>
    59. <el-table-column prop="trainNumber" label="培训人数" align="center" width="80"> el-table-column>
    60. <el-table-column prop="startTime" label="培训开始时间" align="center" :formatter="onRenderTime"> el-table-column>
    61. <el-table-column prop="endTime" label="培训结束时间" align="center" :formatter="onRenderTime"> el-table-column>
    62. <el-table-column prop="isCert" label="是否为机构取证类" align="center" width="50"> el-table-column>
    63. el-table>
    64. <Pagination :total="total" :page.sync="form.pageIndex" :limit.sync="form.pageSize" @pagination="onQuery" />
    65. div>
    66. el-main>
    67. el-container>
    68. template>
    69. <script>
    70. import Pagination from '@/components/Pagination';
    71. import { pageTrainProjByTime, listTrainCountAndTimesByTime } from '@/api/eams/trainStat.js';
    72. export default {
    73. name: 'trainStat',
    74. components: { Pagination },
    75. data() {
    76. return {
    77. timeSpanList: [
    78. {
    79. value: 'year',
    80. label: '年',
    81. },
    82. {
    83. value: 'month',
    84. label: '月',
    85. },
    86. ],
    87. form: {
    88. timeSpan: 'month',
    89. time: [],
    90. yearStart: this.$common.parseTime(new Date(), '{y}'),
    91. yearEnd: this.$common.parseTime(new Date(), '{y}'),
    92. sortField: '', //排序字段
    93. sortOrder: '', //排序方向
    94. pageIndex: 0, //页数
    95. pageSize: 20, //每页数量
    96. },
    97. total: 0, //总数
    98. tableData: [],
    99. sumTrainTime: 0,
    100. sumTrainCount: 0,
    101. myChart: null,
    102. xData: [], //横轴
    103. trainNumChart: [], //培训次数
    104. trainTimeChart: [],
    105. // 校验
    106. rules: {
    107. startTime: [{ required: true, message: '请选择时间', trigger: 'change' }],
    108. endTime: [{ required: true, message: '请选择时间', trigger: 'change' }],
    109. yearStart: [{ required: true, message: '请选择开始年份', trigger: 'change' }],
    110. yearEnd: [{ required: true, message: '请选择结束年份', trigger: 'change' }],
    111. },
    112. };
    113. },
    114. mounted() {
    115. var startDefault = new Date().getFullYear() + '-' + '01';
    116. var endDefault = this.$common.parseTime(new Date(), '{y}-{m}');
    117. this.form.time = [startDefault, endDefault];
    118. //查询
    119. this.myChart = this.$echarts.init(document.getElementById('trainStatCharts'));
    120. let self = this;
    121. this.myChart.on('click', function (params) {
    122. let param = self.getQueryCondition();
    123. param.startTime = params.name;
    124. param.endTime = params.name;
    125. self.pageTrainPlan(param);
    126. });
    127. this.onQuery();
    128. },
    129. methods: {
    130. // 查询
    131. onQuery() {
    132. this.$refs.form.validate((valid) => {
    133. if (valid) {
    134. // if (param.time) {
    135. // param.startTime = this.$common.parseTime(param.time[0], '{y}-{m}-{d}') + ' 00:00:00';
    136. // param.endTime = this.$common.parseTime(param.time[1], '{y}-{m}-{d}') + ' 23:59:59';
    137. // }
    138. const param = this.getQueryCondition();
    139. this.pageTrainPlan(param);
    140. //加载统计培训次数
    141. listTrainCountAndTimesByTime(param).then((res) => {
    142. var resData = res.data.data;
    143. this.sumTrainCount = 0;
    144. this.sumTrainTime = 0;
    145. this.xData = resData.map((item) => {
    146. return item.time;
    147. });
    148. this.trainNumChart = resData.map((item) => {
    149. return item.trainCount;
    150. });
    151. this.trainNumChart.map((item) => (this.sumTrainCount = this.sumTrainCount + item));
    152. this.trainTimeChart = resData.map((item) => {
    153. return item.trainTime;
    154. });
    155. this.trainTimeChart.map((item) => (this.sumTrainTime = this.sumTrainTime + item));
    156. this.onLoadChart();
    157. });
    158. }
    159. });
    160. },
    161. pageTrainPlan(param) {
    162. pageTrainProjByTime(param).then((res) => {
    163. this.tableData = res.data.data ? res.data.data.data : [];
    164. this.total = res.data.data.total;
    165. });
    166. },
    167. //查询条件
    168. getQueryCondition() {
    169. var param = { ...this.form };
    170. if (param.timeSpan == 'year') {
    171. param.startTime = param.yearStart;
    172. param.endTime = param.yearEnd;
    173. } else {
    174. param.startTime = param.time[0];
    175. param.endTime = param.time[1];
    176. }
    177. return param;
    178. },
    179. // 重置
    180. resetForm() {
    181. this.$refs.form.resetFields();
    182. this.onQuery();
    183. },
    184. //表格排序
    185. onSortChanged(column) {
    186. var order = column.order;
    187. this.form.sortField = column.prop;
    188. this.form.sortOrder = order
    189. ? order === 'descending' // 第一个问号:order不为空
    190. ? 'desc'
    191. : 'asc'
    192. : '';
    193. this.onQuery();
    194. },
    195. //表格渲染时间
    196. onRenderTime(row, column, cellValue) {
    197. return this.$common.parseTime(cellValue, '{y}-{m}-{d}');
    198. },
    199. //双击表格行
    200. onTableDblclick(row) {
    201. this.htmlFlag = 'look';
    202. this.selectedRow = row;
    203. this.dialogFormVisible = true;
    204. },
    205. //加载柱状图
    206. onLoadChart() {
    207. //柱状图
    208. //柱状图
    209. var option = {
    210. tooltip: {
    211. trigger: 'axis',
    212. },
    213. grid: {
    214. left: '3%',
    215. right: '5%',
    216. },
    217. legend: {
    218. top: 10,
    219. data: ['培训次数', '培训时长'],
    220. textStyle: {
    221. //color: '#efefef',
    222. },
    223. },
    224. toolbox: {
    225. show: false,
    226. feature: {
    227. dataView: { show: false, readOnly: false },
    228. magicType: { show: true, type: ['line', 'bar'] },
    229. restore: { show: false },
    230. saveAsImage: { show: false },
    231. },
    232. },
    233. calculable: true,
    234. color: ['#59CE98', '#40B3C4', '#5E98EF', '#5640C4', '#BAB25E'],
    235. xAxis: [
    236. {
    237. type: 'category',
    238. // prettier-ignore
    239. data: this.xData,
    240. axisLabel: {
    241. //color: '#efefef',
    242. fontSize: '15px',
    243. },
    244. },
    245. ],
    246. yAxis: [
    247. {
    248. type: 'value',
    249. axisLabel: {
    250. //color: '#efefef',
    251. fontSize: '15px',
    252. },
    253. },
    254. ],
    255. series: [
    256. {
    257. name: '培训次数',
    258. type: 'bar',
    259. data: this.trainNumChart,
    260. label: {
    261. show: true,
    262. position: 'top',
    263. //color: '#efefef',
    264. fontSize: 14,
    265. },
    266. },
    267. {
    268. name: '培训时长',
    269. type: 'bar',
    270. data: this.trainTimeChart,
    271. label: {
    272. show: true,
    273. position: 'top',
    274. //color: '#efefef',
    275. fontSize: 14,
    276. },
    277. },
    278. ],
    279. };
    280. this.myChart.setOption(option);
    281. },
    282. },
    283. };
    284. script>
    285. <style scoped>
    286. .train-plan-index .el-header {
    287. height: auto !important;
    288. }
    289. .upload-plan {
    290. display: inline-block;
    291. margin: 0px 10px;
    292. }
    293. .stat-main {
    294. display: flex;
    295. flex-direction: row;
    296. }
    297. .chart-div {
    298. width: 50%;
    299. height: 100%;
    300. }
    301. .stat-chart-div {
    302. width: 100%;
    303. height: calc(100% - 50px);
    304. }
    305. .stat-text-div {
    306. width: 100%;
    307. height: 50px;
    308. }
    309. .table-div {
    310. width: calc(50% - 10px);
    311. height: 100%;
    312. margin-left: 10px;
    313. }
    314. .year-span {
    315. display: inline-block;
    316. line-height: 32px;
    317. }
    318. .year-span >>> .el-date-editor.el-input {
    319. width: 100px;
    320. }
    321. style>

  • 相关阅读:
    LVGL移植
    基于ubuntu20.04安装ros系统搭配使用工业相机
    力扣刷题之爬楼梯(7/30)
    spring-cloud-alibaba-Nacos2.0.3:注册中心和配置中心框架学习
    前端er须知的Nginx技巧
    基于QT的指挥猫猫打架玩耍的小游戏设计
    【C语言期末不挂科——指针篇1】
    axios的封装
    Win10 桌面图标出现空文件夹的删除及桌面图标排列问题
    5.2.SpringBoot整合Kafka
  • 原文地址:https://blog.csdn.net/qq_42192641/article/details/132983030