Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 feature custom total data pivot table #409

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: support use custom data as summary data #400\n\n",
"type": "patch",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "892739385@qq.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: analysis pivot tree summary value is wrong\n\n",
"type": "patch",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "892739385@qq.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "docs: add analysis rules demos\n\n",
"type": "patch",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "892739385@qq.com"
}
216 changes: 216 additions & 0 deletions docs/assets/demo/en/data-analysis/pivot-analysis-custom-total.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
---
category: examples
group: data-analysis
title: Custom Total
cover: https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/preview/pivot-analysis-custom-total.png
link: '../guide/table_type/Pivot_table/pivot_table_dataAnalysis'
---

# Pivot analysis table—customized summary data

Pivot analysis table data summary, if summary data is passed in the data source record, the table will give priority to using the user-input value as the summary value.

## Key configuration

- `PivotTable`
- `columns`
- `rows`
- `indicators`
- `enableDataAnalysis` turns on pivot data analysis
- `dataConfig` configures data rules, optional configuration items
## Code demo

```javascript livedemo template=vtable

let tableInstance;
fetch('https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/North_American_Superstore_Pivot_Chart_data.json')
.then((res) => res.json())
.then((data) => {
debugger
data = data.concat([
// 追加汇总数据
{
"Region": "Central",
"Segment": "Consumer",
"Category": "Office Supplies",
"Quantity": "1111",
"Sales": "3333",
"Profit": "2222",
},
{
"Region": "Central",
"Category": "Office Supplies",
"Sub-Category": "Appliances",
"Quantity": "1111",
"Sales": "3333",
"Profit": "2222",
},
{
"Region": "Central",
"Quantity": "4444",
"Sales": "6666",
"Profit": "5555",
},
{
"Category": "Office Supplies",
"Quantity": "7777",
"Sales": "9999",
"Profit": "8888",
},
{
"Quantity": "9999",
"Sales": "9999",
"Profit": "9999",
}
])
const option = {
records:data,
"rows": [
{
"dimensionKey": "Category",
"title": "Category",
"headerStyle": {
"textStick": true
},
"width": "auto",
},
{
"dimensionKey": "Sub-Category",
"title": "Sub-Catogery",
"headerStyle": {
"textStick": true
},
"width": "auto",
},
],
"columns": [
{
"dimensionKey": "Region",
"title": "Region",
"headerStyle": {
"textStick": true
},
"width": "auto",
},
{
"dimensionKey": "Segment",
"title": "Segment",
"headerStyle": {
"textStick": true
},
"width": "auto",
},
],
"indicators": [
{
"indicatorKey": "Quantity",
"title": "Quantity",
"width": "auto",
"showSort": false,
"headerStyle":{
fontWeight: "normal",
},
style:{
padding:[16,28,16,28],
color(args){
if(args.dataValue>=0)
return 'black';
return 'red'
},
bgColor(arg) {
const rowHeaderPaths = arg.cellHeaderPaths.rowHeaderPaths;
if (rowHeaderPaths?.[1]?.value === 'Sub Totals') {
return '#ba54ba';
} else if (rowHeaderPaths?.[0]?.value === 'Row Totals') {
return '#ff9900';
}
return undefined;
}
}
},
{
"indicatorKey": "Sales",
"title": "Sales",
"width": "auto",
"showSort": false,
"headerStyle":{
fontWeight: "normal",
},
"format":(rec)=>{return '$'+Number(rec).toFixed(2)},
style:{
padding:[16,28,16,28],
color(args){
if(args.dataValue>=0)
return 'black';
return 'red'
},
bgColor(arg) {
const rowHeaderPaths = arg.cellHeaderPaths.rowHeaderPaths;
if (rowHeaderPaths?.[1]?.value === 'Sub Totals') {
return '#ba54ba';
} else if (rowHeaderPaths?.[0]?.value === 'Row Totals') {
return '#ff9900';
}
return undefined;
}
}
},
{
"indicatorKey": "Profit",
"title": "Profit",
"width": "auto",
"showSort": false,
"headerStyle":{
fontWeight: "normal",
},
"format":(rec)=>{return '$'+Number(rec).toFixed(2)},
style:{
padding:[16,28,16,28],
color(args){
if(args.dataValue>=0)
return 'black';
return 'red'
},
bgColor(arg) {
const rowHeaderPaths = arg.cellHeaderPaths.rowHeaderPaths;
if (rowHeaderPaths?.[1]?.value === 'Sub Totals') {
return '#ba54ba';
} else if (rowHeaderPaths?.[0]?.value === 'Row Totals') {
return '#ff9900';
}
return undefined;
}
}
}
],
"corner": {
"titleOnDimension": "row",
"headerStyle": {
"textStick": true
}
},
dataConfig: {
totals: {
row: {
showGrandTotals: true,
showSubTotals: true,
subTotalsDimensions: ['Category'],
grandTotalLabel: 'Row Totals',
subTotalLabel: 'Sub Totals'
},
column: {
showGrandTotals: true,
showSubTotals: true,
subTotalsDimensions: ['Region'],
grandTotalLabel: 'Column Totals',
subTotalLabel: 'Sub Totals'
}
},
},
enableDataAnalysis: true,
widthMode:'standard'
};
tableInstance = new VTable.PivotTable(document.getElementById(CONTAINER_ID),option);
window['tableInstance'] = tableInstance;
})
```
Loading