零售指标

下面的例子展示了如何使用SpreadJS的电子表格为JavaScript应用创建一个销售业绩仪表盘的过程,例如呈现一个销售指标摘要。这个演示展现了区域模板的强大能力,它允许你定义一个多行的模板,并且将这个模板应用到单元格上。

该示例演示了如何使用区域模板显示迷你图。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 5 }); initSpread(spread); }; function initSpread(spread) { if (!spread) { return; } spread.suspendPaint(); let sheet1 = spread.getSheet(1); let sheet2 = spread.getSheet(2); let sheet3 = spread.getSheet(3); let sheet4 = spread.getSheet(4); sheet1.fromJSON(line_templatejson); sheet2.fromJSON(column_templatejson); sheet3.fromJSON(area_templatejson); sheet4.fromJSON(des_templatejson); var sheet = spread.getSheet(0), line_ct = new GC.Spread.Sheets.CellTypes.RangeTemplate(sheet1, 0, 0, 10, 5), column_ct = new GC.Spread.Sheets.CellTypes.RangeTemplate(sheet2, 0, 0, 10, 5), area_ct = new GC.Spread.Sheets.CellTypes.RangeTemplate(sheet3, 0, 0, 10, 5), desc_ct = new GC.Spread.Sheets.CellTypes.RangeTemplate(sheet4, 0, 0, 4, 1); sheet.name("Metrics"); var data = [{ title: "Sales per Square foot", money: 311.76, percent: 0.04, data: { item1: 300, item2: 20, item3: 310, item4: 360, item5: 420, item6: 500, item7: 425, item8: 430, item9: 420, item10: 425 } }, { title: "Sales per Hour", money: 12745.11, percent: 0.27, data: { item1: 300, item2: 400, item3: 340, item4: 500, item5: 200, item6: 380, item7: 240, item8: 420, item9: 320, item10: 430 } }, { title: "Average Price", money: 17.55, percent: -0.02, data: { item1: 200, item2: 300, item3: 280, item4: 450, item5: 250, item6: 180, item7: 290, item8: 300, item9: 320, item10: 270 } }, { title: "Avg Sale per Customer", money: 179, percent: -0.03, data: { item1: 30, item2: 38, item3: 4, item4: 10, item5: 6, item6: 12, item7: 18, item8: 7, item9: 16, item10: 12 } }, { title: "Avg Minutes in Store", money: 8.32, percent: -0.17, data: { item1: 150, item2: 370, item3: -60, item4: 10, item5: -190, item6: 40, item7: 50, item8: 130, item9: -70, item10: 0 } }, { title: "Top Product Score", money: 320, percent: 0.23, data: { item1: 1, item2: 3, item3: 5, item4: 8, item5: 3, item6: 2, item7: 1, item8: 1, item9: 2, item10: 1 } }, { title: "Avg Units per Customer", money: 4.31, percent: -0.14, data: { item1: 1, item2: 3, item3: 8, item4: 2, item5: 8, item6: 2, item7: 9, item8: 3, item9: 7, item10: 4 } }, { title: "Top Region", area: "North America" }]; sheet.options.gridline.showHorizontalGridline = false; sheet.options.gridline.showVerticalGridline = false; sheet.setColumnWidth(0, 220); sheet.setColumnWidth(2, 220); sheet.setColumnWidth(4, 220); sheet.setColumnWidth(6, 220); sheet.setColumnWidth(1, 15); sheet.setColumnWidth(3, 15); sheet.setColumnWidth(5, 15); sheet.setRowHeight(1, 150); sheet.setRowHeight(2, 15); sheet.setRowHeight(3, 150); sheet.setRowHeight(0, 30); sheet.getCell(0, 0).hAlign(1).vAlign(1).font("bold 18pt Calibri").value("Retail Metrics"); sheet.getCell(1, 0).cellType(line_ct).value(data[0]); sheet.getCell(1, 2).cellType(column_ct).value(data[1]); sheet.getCell(1, 4).cellType(line_ct).value(data[2]); sheet.getCell(1, 6).cellType(area_ct).value(data[5]); sheet.getCell(3, 0).cellType(column_ct).value(data[4]); sheet.getCell(3, 2).cellType(line_ct).value(data[3]); sheet.getCell(3, 4).cellType(column_ct).value(data[6]); sheet.getCell(3, 6).cellType(desc_ct).value(data[7]); spread.resumePaint(); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <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-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/range-template.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" style="width:100%;height:100%"></div> </div> </body> </html>