-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pivot table support not number type #718
- Loading branch information
Showing
5 changed files
with
362 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
334 changes: 334 additions & 0 deletions
334
packages/vtable/examples/pivot-analysis/pivot-analysis-str.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,334 @@ | ||
import * as VTable from '../../src'; | ||
const PivotTable = VTable.PivotTable; | ||
const CONTAINER_ID = 'vTable'; | ||
import { animalImageUrl, flowerVideoUrl } from '../resource-url'; | ||
const sumNumberFormat = VTable.DataStatistics.numberFormat({ | ||
suffix: '元' | ||
}); | ||
const countNumberFormat = VTable.DataStatistics.numberFormat({ | ||
digitsAfterDecimal: 0, | ||
thousandsSep: '', | ||
suffix: '单' | ||
}); | ||
export function createTable() { | ||
const option: VTable.PivotTableConstructorOptions = { | ||
rows: ['province', 'city'], | ||
columns: ['category', 'sub_category'], | ||
indicators: ['销售总额', '订单数', '订单均价'], | ||
enableDataAnalysis: true, | ||
indicatorTitle: '指标名称', | ||
indicatorsAsCol: false, | ||
dataConfig: { | ||
aggregationRules: [ | ||
//做聚合计算的依据,如销售额如果没有配置则默认按聚合sum计算结果显示单元格内容 | ||
{ | ||
indicatorKey: '销售总额', //指标名称 | ||
field: 'sales', //指标依据字段 | ||
aggregationType: VTable.TYPES.AggregationType.NONE //计算类型 | ||
}, | ||
{ | ||
indicatorKey: '订单数', //指标名称 | ||
field: 'sales', //指标依据字段 | ||
aggregationType: VTable.TYPES.AggregationType.COUNT, //计算类型 | ||
formatFun: countNumberFormat | ||
}, | ||
{ | ||
indicatorKey: '订单均价', //指标名称 | ||
field: 'sales', //指标依据字段 | ||
aggregationType: VTable.TYPES.AggregationType.AVG, //计算类型 | ||
formatFun: sumNumberFormat | ||
} | ||
] | ||
}, | ||
corner: { titleOnDimension: 'row' }, | ||
records: [ | ||
{ | ||
sales: 'rrr', | ||
number: 7789, | ||
province: '浙江省', | ||
city: '杭州市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 1891, | ||
number: 7789, | ||
province: '浙江省', | ||
city: '杭州市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 792, | ||
number: 2367, | ||
province: '浙江省', | ||
city: '绍兴市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 893, | ||
number: 3877, | ||
province: '浙江省', | ||
city: '宁波市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 1094, | ||
number: 4342, | ||
province: '浙江省', | ||
city: '舟山市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 1295, | ||
number: 5343, | ||
province: '浙江省', | ||
city: '杭州市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 496, | ||
number: 632, | ||
province: '浙江省', | ||
city: '绍兴市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 1097, | ||
number: 7234, | ||
province: '浙江省', | ||
city: '宁波市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 998, | ||
number: 834, | ||
province: '浙江省', | ||
city: '舟山市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 766, | ||
number: 945, | ||
province: '浙江省', | ||
city: '杭州市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 990, | ||
number: 1304, | ||
province: '浙江省', | ||
city: '绍兴市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 891, | ||
number: 1145, | ||
province: '浙江省', | ||
city: '宁波市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 792, | ||
number: 1432, | ||
province: '浙江省', | ||
city: '舟山市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 745, | ||
number: 1343, | ||
province: '浙江省', | ||
city: '杭州市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: 843, | ||
number: 1354, | ||
province: '浙江省', | ||
city: '绍兴市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: 895, | ||
number: 1523, | ||
province: '浙江省', | ||
city: '宁波市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: 965, | ||
number: 1634, | ||
province: '浙江省', | ||
city: '舟山市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: 776, | ||
number: 1723, | ||
province: '四川省', | ||
city: '成都市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 634, | ||
number: 1822, | ||
province: '四川省', | ||
city: '绵阳市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 909, | ||
number: 1943, | ||
province: '四川省', | ||
city: '南充市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 399, | ||
number: 2330, | ||
province: '四川省', | ||
city: '乐山市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 478, | ||
number: 1900, | ||
province: '四川省', | ||
city: '乐山市', | ||
category: '家具', | ||
sub_category: '桌子' | ||
}, | ||
{ | ||
sales: 700, | ||
number: 2451, | ||
province: '四川省', | ||
city: '成都市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 689, | ||
number: 2244, | ||
province: '四川省', | ||
city: '绵阳市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 500, | ||
number: 2333, | ||
province: '四川省', | ||
city: '南充市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 800, | ||
number: 2445, | ||
province: '四川省', | ||
city: '乐山市', | ||
category: '家具', | ||
sub_category: '沙发' | ||
}, | ||
{ | ||
sales: 1044, | ||
number: 2335, | ||
province: '四川省', | ||
city: '成都市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 689, | ||
number: 245, | ||
province: '四川省', | ||
city: '绵阳市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 794, | ||
number: 2457, | ||
province: '四川省', | ||
city: '南充市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 566, | ||
number: 2458, | ||
province: '四川省', | ||
city: '乐山市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: animalImageUrl, | ||
number: 1458, | ||
province: '四川省', | ||
city: '乐山市', | ||
category: '办公用品', | ||
sub_category: '笔' | ||
}, | ||
{ | ||
sales: 865, | ||
number: 4004, | ||
province: '四川省', | ||
city: '成都市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: animalImageUrl, | ||
number: 3077, | ||
province: '四川省', | ||
city: '绵阳市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: animalImageUrl, | ||
number: 3551, | ||
province: '四川省', | ||
city: '南充市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
}, | ||
{ | ||
sales: animalImageUrl, | ||
number: 352, | ||
province: '四川省', | ||
city: '乐山市', | ||
category: '办公用品', | ||
sub_category: '纸张' | ||
} | ||
], | ||
widthMode: 'autoWidth' // 宽度模式:standard 标准模式; adaptive 自动填满容器 | ||
}; | ||
|
||
const instance = new PivotTable(document.getElementById(CONTAINER_ID)!, option); | ||
window.tableInstance = instance; | ||
|
||
// 只为了方便控制太调试用,不要拷贝 | ||
window.tableInstance = instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.