Verified Commit 8b0b9268 authored by jxtxzzw's avatar jxtxzzw

Feature: Income Basic Accumulated

Signed-off-by: jxtxzzw's avatarjxtxzzw <jxtxzzw@126.com>
parent 686aafc3
......@@ -11,7 +11,7 @@
"year": "2019",
"amount": "20",
"type": "酬金",
"category": "项目津贴"
"category": "科研津贴"
},
{
"id": "3",
......@@ -22,16 +22,23 @@
},
{
"id": "4",
"year": "2020",
"year": "2019",
"amount": "30",
"type": "酬金",
"category": "科研津贴"
"category": "项目津贴"
},
{
"id": "5",
"year": "2020",
"year": "2019",
"amount": "30",
"type": "酬金2",
"category": "科研津贴"
"type": "工资",
"category": "奖金"
},
{
"id": "6",
"year": "2021",
"amount": "30",
"type": "工资",
"category": "基本工资"
}
]
......@@ -172,3 +172,68 @@ export function renderChartForBasicCategory(that, rawData) {
chart.render()
}
function getDataForBasicAccumulated(rawData) {
const dict = {}
let minYear = 9999
let maxYear = 0
for (const x of rawData) {
const year = parseInt(x.year)
const amount = parseFloat(x.amount)
if (year < minYear) {
minYear = year
}
if (year > maxYear) {
maxYear = year
}
if (!(year in dict)) {
dict[year] = 0
}
dict[year] += amount
}
const data = []
let sum = 0
for (let i = minYear; i <= maxYear; i++) {
if (i in dict) {
sum += dict[i]
}
data.push({
year: i,
value: sum,
})
}
return data
}
export function renderChartForBasicAccumulated(that, rawData) {
const { Chart } = that.$g2
const data = getDataForBasicAccumulated(rawData)
const chart = new Chart({
container: 'basic-accumulated',
autoFit: true,
height: 500,
})
chart.data(data)
chart.scale({
year: {
range: [0, 1],
},
value: {
min: 0,
nice: true,
},
})
chart.tooltip({
showCrosshairs: true, // 展示 Tooltip 辅助线
shared: true,
})
chart.line().position('year*value').label('value')
chart.point().position('year*value')
chart.render()
}
......@@ -196,6 +196,7 @@
},
"income": {
"basic-year": "Income for each year",
"basic-category": "Income for categories"
"basic-category": "Income for categories",
"basic-accumulated": "Accumulated incomes"
}
}
......@@ -196,6 +196,7 @@
},
"income": {
"basic-year": "每年收入",
"basic-category": "收入类型"
"basic-category": "收入类型",
"basic-accumulated": "收入汇总"
}
}
......@@ -4,6 +4,7 @@
<div id="basic-year"></div>
<Divider>{{ $t('income.basic-category') }} </Divider>
<div id="basic-category"></div>
<Divider>{{ $t('income.basic-accumulated') }} </Divider>
<div id="basic-accumulated"></div>
<div id="advanced-year"></div>
<div id="advanced-platform"></div>
......@@ -19,6 +20,7 @@ export default {
mounted() {
incomeUtil.renderChartForBasicYear(this, income)
incomeUtil.renderChartForBasicCategory(this, income)
incomeUtil.renderChartForBasicAccumulated(this, income)
// Chart 都是 autoFit 的,所以强制触发一次 resize 就可以了
window.dispatchEvent(new Event('resize'))
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment