交叉表

dev
黄欣 4 years ago
parent 87c4e50bcf
commit c3cf941b17

@ -197,6 +197,11 @@ public class ChartViewService {
}.getType());
yAxis.addAll(yAxisExt);
}
if (StringUtils.equalsIgnoreCase(view.getType(), "table-normal")) {
List<ChartViewFieldDTO> yAxisExt = new Gson().fromJson(view.getYAxisExt(), new TypeToken<List<ChartViewFieldDTO>>() {
}.getType());
xAxis.addAll(yAxisExt);
}
List<ChartViewFieldDTO> extStack = new Gson().fromJson(view.getExtStack(), new TypeToken<List<ChartViewFieldDTO>>() {
}.getType());
List<ChartViewFieldDTO> extBubble = new Gson().fromJson(view.getExtBubble(), new TypeToken<List<ChartViewFieldDTO>>() {

Binary file not shown.

@ -11,7 +11,10 @@
:width-resize="true"
:header-row-style="table_header_class"
:row-style="getRowStyle"
:cell-style="getColumStyle"
class="table-class"
show-overflow="tooltip"
show-header-overflow="tooltip"
:class="chart.id"
:show-summary="showSummary"
:summary-method="summaryMethod"
@ -19,15 +22,13 @@
<ux-table-column
v-for="(field, index) in fields"
:key="index"
:min-width="field.rowName?200:100"
:field="field.dataeaseName"
:resizable="true"
sortable
:title="field.name"
>
<!-- <template slot="header">-->
<!-- <span>{{ field.name }}</span>-->
<!-- </template>-->
</ux-table-column>
:sortable="!field.rowName"
:fixed="field.fixed"
:title="field.rowName?field.name+' \\ '+field.rowName:field.name"
/>
</ux-grid>
<el-row v-show="chart.type === 'table-info'" class="table-page">
@ -97,7 +98,7 @@ export default {
table_header_class: {
fontSize: '12px',
color: '#606266',
background: '#e8eaec',
backgroundColor: '#e8eaec',
height: '36px'
},
table_item_class: {
@ -162,15 +163,66 @@ export default {
const that = this
let datas = []
if (this.chart.data) {
console.log(this.chart)
this.fields = JSON.parse(JSON.stringify(this.chart.data.fields))
datas = JSON.parse(JSON.stringify(this.chart.data.tableRow))
const findRowIndex = this.fields.findIndex(e => e.chartType === 'row')
const findValueIndex = this.fields.findIndex(e => e.chartType === 'bar')
const findIndex = this.fields.findIndex(e => e.chartType === null)
if (this.chart.type === 'table-info') {
//
this.currentPage.show = datas.length
const pageStart = (this.currentPage.page - 1) * this.currentPage.pageSize
const pageEnd = pageStart + this.currentPage.pageSize
datas = datas.slice(pageStart, pageEnd)
} else if (this.chart.type === 'table-normal' && findRowIndex >= 0) {
//
this.fields[0].rowName = this.fields[findRowIndex].name
this.fields[0].fixed = 'left'
const fieldRowName = this.fields[findRowIndex].dataeaseName
const fieldValueName = this.fields[findValueIndex].dataeaseName
const fieldName = this.fields[findIndex].dataeaseName
const fields = [this.fields[0]]
let name = null
let flag = true
let rowSum = 0
const columnValue = []
datas.forEach((ele, index) => {
if (name !== ele[fieldName] && name !== null) {
flag = false
}
if (name !== ele[fieldName]) {
columnValue.push({
[fieldName]: ele[fieldName]
})
}
name = ele[fieldName]
if (name === ele[fieldName] && flag) {
fields.push({
dataeaseName: fieldRowName + ele[fieldRowName],
name: ele[fieldRowName]
})
}
})
columnValue.forEach(ele => {
datas.forEach(subEle => {
if (ele[fieldName] === subEle[fieldName]) {
const key = fieldRowName + subEle[fieldRowName]
ele[key] = subEle[fieldValueName]
rowSum += subEle[fieldValueName]
}
})
ele.rowTotal = rowSum
rowSum = 0
})
fields.push({
dataeaseName: 'rowTotal',
fixed: 'right',
name: `合计(${this.fields[findValueIndex].name})`
})
datas = columnValue
this.fields = fields
console.log(columnValue)
console.log(fields)
}
} else {
this.fields = []
@ -222,7 +274,7 @@ export default {
const customAttr = JSON.parse(this.chart.customAttr)
if (customAttr.color) {
this.table_header_class.color = customAttr.color.tableFontColor
this.table_header_class.background = hexColorToRGBA(customAttr.color.tableHeaderBgColor, customAttr.color.alpha)
this.table_header_class.backgroundColor = hexColorToRGBA(customAttr.color.tableHeaderBgColor, customAttr.color.alpha)
this.table_item_class.color = customAttr.color.tableFontColor
this.table_item_class.background = hexColorToRGBA(customAttr.color.tableItemBgColor, customAttr.color.alpha)
}
@ -265,7 +317,7 @@ export default {
// console.log(s_table)
let s = ''
for (const i in this.table_header_class) {
s += (i === 'fontSize' ? 'font-size' : i) + ':' + this.table_header_class[i] + ';'
s += (i === 'fontSize' ? 'font-size' : i === 'backgroundColor' ? 'background-color' : i) + ':' + this.table_header_class[i] + ';'
}
// console.log(s_table)
for (let i = 0; i < s_table.length; i++) {
@ -280,14 +332,28 @@ export default {
return this.table_item_class
}
},
getColumStyle({ columnIndex }) {
const findRowIndex = this.fields.findIndex(e => e.rowName)
if (this.chart.type === 'table-normal' && findRowIndex >= 0 && (columnIndex === 0 || columnIndex === this.fields.length - 1)) {
return this.table_header_class
} else {
return ''
}
},
summaryMethod({ columns, data }) {
const that = this
const means = [] //
const findRowIndex = this.fields.findIndex(e => e.rowName)
const findValueIndex = this.chart.data.fields.findIndex(e => e.chartType === 'bar')
columns.forEach((column, columnIndex) => {
if (columnIndex === 0) {
means.push('合计')
if (findRowIndex !== -1 && findValueIndex !== -1) {
means.push(`合计(${this.chart.data.fields[findValueIndex].name})`)
} else {
means.push('合计')
}
} else {
if (columnIndex >= that.chart.data.fields.length - that.chart.data.series.length) {
if (columnIndex >= that.chart.data.fields.length - that.chart.data.series.length || findRowIndex !== -1) {
const values = data.map(item => Number(item[column.property]))
//
if (!values.every(value => isNaN(value))) {
@ -375,4 +441,10 @@ export default {
.page-style >>> .el-input__inner{
height: 24px;
}
.colum-header {
font-size: 12px;
color: #000;
background: rgb(78, 129, 187);
height: 36px;
}
</style>

@ -106,11 +106,11 @@
@change="save(true,'chart',true,true)"
>
<div class="chart-radio-div" style="width: 100%;display: flex;display: -webkit-flex;justify-content: space-between;flex-direction: row;flex-wrap: wrap;">
<!-- <el-radio value="table-normal" label="table-normal">
<el-radio value="table-normal" label="table-normal">
<span :title="$t('chart.chart_table_normal')">
<svg-icon icon-class="table-normal" class="chart-icon" />
</span>
</el-radio> -->
</el-radio>
<el-radio value="table-info" label="table-info">
<span :title="$t('chart.chart_table_info')">
<svg-icon icon-class="table-info" class="chart-icon" />
@ -158,16 +158,16 @@
</div>
<div style="width: 100%;display: flex;display: -webkit-flex;justify-content: space-between;flex-direction: row;flex-wrap: wrap;">
<el-radio value="map" label="map">
<span :title="$t('chart.chart_map')">
<svg-icon icon-class="map" class="chart-icon" />
</span>
</el-radio>
<!-- <el-radio value="radar" label="radar">-->
<!-- <span :title="$t('chart.chart_radar')">-->
<!-- <svg-icon icon-class="radar" class="chart-icon" />-->
<!-- </span>-->
<!-- </el-radio>-->
<el-radio value="map" label="map">
<span :title="$t('chart.chart_map')">
<svg-icon icon-class="map" class="chart-icon" />
</span>
</el-radio>
<!-- <el-radio value="radar" label="radar">
<span :title="$t('chart.chart_radar')">
<svg-icon icon-class="radar" class="chart-icon" />
</span>
</el-radio> -->
<el-radio value="scatter" label="scatter">
<span :title="$t('chart.chart_scatter')">
<svg-icon icon-class="scatter" class="chart-icon" />
@ -183,8 +183,6 @@
<svg-icon icon-class="liquid" class="chart-icon" />
</span>
</el-radio>
</div>
<div style="width: 100%;display: flex;display: -webkit-flex;justify-content: space-between;flex-direction: row;flex-wrap: wrap;">
<el-radio value="gauge" label="gauge">
@ -212,7 +210,7 @@
<svg-icon icon-class="treemap" class="chart-icon" />
</span>
</el-radio>
<!-- <el-radio value="" label="" disabled class="disabled-none-cursor"><svg-icon icon-class="" class="chart-icon" /></el-radio>-->
<!-- <el-radio value="" label="" disabled class="disabled-none-cursor"><svg-icon icon-class="" class="chart-icon" /></el-radio> -->
</div>
<!-- <div style="width: 100%;display: flex;display: -webkit-flex;justify-content: space-between;flex-direction: row;flex-wrap: wrap;">-->
<!-- <el-radio value="" label="" disabled class="disabled-none-cursor"><svg-icon icon-class="" class="chart-icon" /></el-radio>-->
@ -942,7 +940,26 @@ export default {
ele.filter = []
}
})
if (view.type === 'chart-mix' || view.type === 'table-normal') {
if (view.type === 'table-normal') {
view.yaxisExt.forEach(function(ele) {
if (!ele.chartType) {
ele.chartType = 'row'
}
if (!ele.dateStyle || ele.dateStyle === '') {
ele.dateStyle = 'y_M_d'
}
if (!ele.datePattern || ele.datePattern === '') {
ele.datePattern = 'date_sub'
}
if (!ele.sort || ele.sort === '') {
ele.sort = 'none'
}
if (!ele.filter) {
ele.filter = []
}
})
}
if (view.type === 'chart-mix') {
view.yaxisExt.forEach(function(ele) {
if (!ele.chartType) {
ele.chartType = 'bar'
@ -1068,10 +1085,6 @@ export default {
this.view.customAttr = this.view.customAttr ? JSON.parse(this.view.customAttr) : {}
this.view.customStyle = this.view.customStyle ? JSON.parse(this.view.customStyle) : {}
this.view.customFilter = this.view.customFilter ? JSON.parse(this.view.customFilter) : {}
console.log(this.view.xaxis)
console.log(this.view.yaxis)
console.log(this.view.yaxisExt)
console.log(this.view.type)
// echart
this.chart = response.data
this.data = response.data.data
@ -1427,7 +1440,7 @@ export default {
}
},
addXaxis(e) {
if (this.view.type === 'map' && this.view.xaxis.length > 1) {
if ((this.view.type === 'map' && this.view.xaxis.length > 1) || (this.view.type === 'table-normal' && this.view.xaxis.length > 1 && this.view.yaxisExt.length > 0)) {
this.view.xaxis = [this.view.xaxis[0]]
}
if (this.view.type !== 'table-info') {
@ -1437,13 +1450,21 @@ export default {
this.save(true)
},
addRowXaxis(e) {
this.view.yaxisExt = [this.view.yaxisExt[0]]
if (this.view.yaxisExt.length > 1) {
this.view.yaxisExt = [this.view.yaxisExt[0]]
}
if (this.view.xaxis.length > 1) {
this.view.xaxis = [this.view.xaxis[0]]
}
if (this.view.yaxis.length > 1) {
this.view.yaxis = [this.view.yaxis[0]]
}
this.dragCheckType(this.view.yaxisExt, 'd')
this.dragMoveDuplicate(this.view.yaxisExt, e)
this.save(true)
},
addYaxis(e) {
if (this.view.type === 'map' && this.view.yaxis.length > 1) {
if ((this.view.type === 'map' && this.view.yaxis.length > 1) || (this.view.type === 'table-normal' && this.view.yaxis.length > 1 && this.view.yaxisExt.length > 0)) {
this.view.yaxis = [this.view.yaxis[0]]
}
this.dragCheckType(this.view.yaxis, 'q')

Loading…
Cancel
Save