数据透视表主题

数据透视表支持三种类型的主题,包括浅色、中等色和深色。 总共支持85种不同的主题。 尝试通过下面的演示更改主题。

您可以通过以下方式更改数据透视表主题:
window.onload = function () { let spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 2}); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); let sheet1 = spread.getSheet(0); let sheet2 = spread.getSheet(1); let tableName = getDataSource(sheet2, pivotSales); let pivotTable = initPivotTable(sheet1, tableName); themeOptions(); bindEvent(pivotTable); autofit(sheet1); autofit(sheet2); spread.resumePaint(); } function getDataSource(sheet, tableSource){ sheet.name("DataSource"); sheet.setRowCount(700); sheet.setColumnWidth(5, 150); let table = sheet.tables.add('table', 0, 0, 642, 6); sheet.setArray(0, 0, tableSource); return table.name(); } function initPivotTable(sheet, source){ sheet.name("PivotTable"); sheet.setRowCount(10000); sheet.setColumnWidth(0, 20); let option = { bandRows:true, bandColumns:true }; let pivotTable = sheet.pivotTables.add("pivotTable", source, 1, 1, GC.Spread.Pivot.PivotTableLayoutType.outline, GC.Spread.Pivot.PivotTableThemes.medium1,option); pivotTable.add("region", "region", GC.Spread.Pivot.PivotTableFieldType.rowField); pivotTable.add("country", "country", GC.Spread.Pivot.PivotTableFieldType.rowField); pivotTable.add("date", "date", GC.Spread.Pivot.PivotTableFieldType.columnField); let groupInfo = { originFieldName: "date", dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }, { by: GC.Pivot.DateGroupType.years }] }; pivotTable.group(groupInfo); pivotTable.add("Years", "Years", GC.Spread.Pivot.PivotTableFieldType.columnField); pivotTable.add("amount", "Sum of amount", GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum); return pivotTable; } function autofit(sheet){ let columnCount = sheet.getColumnCount(); for (let i = 1; i < columnCount; i++) { sheet.autoFitColumn(i); } } function bindEvent(pivotTable){ document.getElementById("pivotTable-theme").addEventListener("change", function(event){ let target = event.target; pivotTable.theme(target.value); }); } function themeOptions(){ let pivotTableTheme = document.getElementById("pivotTable-theme"); let options = `<option themeNumber = 0>light1</option>`; let themeType = ["light","medium","dark"]; let count = 1, checked = "", num = 0; for (let i = 0; i< themeType.length; i++){ num = 0; if(i === 0){ num = 1; } for (let n = 1; n <= 28; n++) { checked = ""; if(i === 1 && n === 1){ checked = "selected"; } options += `<option ${checked}>${themeType[i]+(num + n)}</option>`; count++; } } pivotTableTheme.innerHTML = options; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="spreadjs culture" content="zh-cn" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets-pivot-addon/dist/gc.spread.pivot.pivottables.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/data.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/pivotSales.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div id="container" class="select-theme"> <div>Select a PivotTable theme:</div> <select name="theme" id="pivotTable-theme"></select> </div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .select-theme { width: 280px; height: 100%; padding: 12px; float: right; box-sizing: border-box; background: #fbfbfb; overflow: auto; } #pivotTable-theme { display: block; width: 250px; margin-top: 10px; }