gtsoft-snail-job-server/frontend/src/components/Charts/JobLine.vue

88 lines
2.0 KiB
Vue
Raw Normal View History

2023-01-14 20:46:02 +08:00
<template>
<div>
<div id="jobViewData"></div>
2023-01-14 20:46:02 +08:00
</div>
</template>
<script>
import * as G2 from '@antv/g2'
import { getDashboardJobLine } from '@/api/manage'
2023-01-14 20:46:02 +08:00
const DataSet = require('@antv/data-set')
export default {
name: 'JobLine',
2023-01-14 20:46:02 +08:00
data () {
return {
viewRecords: [],
dashboardLineResponseDOList: [],
2023-01-14 20:46:02 +08:00
chart: null
}
},
mounted () {
this.getDashboardJobLine()
2023-01-14 20:46:02 +08:00
this.createView()
},
methods: {
getDashboardJobLine (groupName, type = 'WEEK', startTime, endTime) {
getDashboardJobLine({
'groupName': groupName,
'type': type,
'startTime': startTime,
'endTime': endTime
}).then(res => {
this.$bus.$emit('job', res)
this.viewCharts(res.data.dashboardLineResponseDOList)
2023-01-14 20:46:02 +08:00
})
},
viewCharts (viewRecords, type = 'WEEK') {
2023-01-14 20:46:02 +08:00
var ds = new DataSet()
2023-01-14 20:46:22 +08:00
if (viewRecords === undefined || viewRecords === null) {
return
}
2023-01-14 20:46:02 +08:00
var dv = ds.createView().source(viewRecords)
dv.transform({
type: 'fold',
fields: ['success', 'fail', 'stop', 'cancel'],
2023-01-14 20:46:02 +08:00
key: 'name',
value: 'viewTotal',
retains: ['total', 'createDt']
2023-01-14 20:46:02 +08:00
})
this.chart.source(dv, {
date: {
type: 'cat'
}
})
this.chart.axis('viewTotal', {
label: {
textStyle: {
fill: '#aaaaaa'
}
}
})
this.chart.tooltip({
crosshairs: {
type: 'line'
}
})
this.chart.line().position('createDt*viewTotal').color('name', ['#1890ff', '#c28c62']).shape('smooth')
this.chart.point().position('createDt*viewTotal').color('name', ['#1890ff', '#c28c62']).size(4).shape('circle').style({
stroke: '#fff',
lineWidth: 1
})
this.chart.render()
},
createView () {
this.chart = new G2.Chart({
container: 'jobViewData',
2023-01-14 20:46:02 +08:00
forceFit: true,
height: 410,
padding: [20, 90, 60, 50]
})
}
}
}
</script>