Plot Area

You can customize the Plot Area, including the border, color, and layout.

Plot area supports the following customization: Background: color, transparency. Border: color, transparency, width, dash style. Layout: x, y, width, height. You can customize the plot area using the following code:
window.onload = function () { const spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 }); initSpread(spread); initEvent(spread); }; function initSpread(spread) { const sheet = spread.getSheet(0); sheet.suspendPaint(); sheet.setArray(0, 0, [ ["", 'Chrome', 'Firefox', 'IE', 'Safari', 'Edge', 'Opera', 'Other'], ["2014", 0.4966, 0.1801, 0.2455, 0.0470, 0.0, 0.0150, 0.0158], ["2015", 0.5689, 0.1560, 0.1652, 0.0529, 0.0158, 0.0220, 0.0192], ["2016", 0.6230, 0.1531, 0.1073, 0.0464, 0.0311, 0.0166, 0.0225], ["2017", 0.6360, 0.1304, 0.0834, 0.0589, 0.0443, 0.0223, 0.0246] ]); const chart = sheet.charts.add('chart', GC.Spread.Sheets.Charts.ChartType.columnClustered, 30, 120, 480, 270, 'A1:D5', GC.Spread.Sheets.Charts.RowCol.columns); chart.title({ text: 'Plot Area Customization' }); chart.plotArea({ backColor: '#FF0000', backColorTransparency: 0.6, border: { color: '#00FF00', width: 3, }, layout: { x: 0.12, y: 0.16, width: 0.76, height: 0.68 } }); chart.isSelected(true); readSetting(chart); sheet.resumePaint(); }; function initEvent(spread) { spread.bind(GC.Spread.Sheets.Events.FloatingElementSelected, function () { var sheet = spread.getActiveSheet(); var chart = getActiveChart(sheet); if (chart) { readSetting(chart); } }); _getElementById("apply").addEventListener('click', function () { applySetting(spread); }); }; function readSetting(chart) { const plotArea = chart.plotArea(); _getElementById("backColor").value = normalizeColor(plotArea.backColor, "#FF0000"); _getElementById("backColorTransparency").value = plotArea.backColorTransparency; _getElementById("border-color").value = normalizeColor(plotArea.border.color, "#00FF00"); _getElementById("border-transparency").value = plotArea.border.transparency; _getElementById("border-width").value = plotArea.border.width; _getElementById("border-dashStyle").value = plotArea.border.dashStyle; const layout = plotArea.layout || {}; _setInputValue("layoutX", layout.x); _setInputValue("layoutY", layout.y); _setInputValue("layoutWidth", layout.width); _setInputValue("layoutHeight", layout.height); } function applySetting(spread) { const sheet = spread.getActiveSheet(); const chart = getActiveChart(sheet); if (!chart) { return; } chart.plotArea({ backColor: _getText("backColor"), backColorTransparency: _getFloat("backColorTransparency"), border:{ color: _getText("border-color"), width: _getValue("border-width"), transparency: _getFloat("border-transparency"), dashStyle: _getValue("border-dashStyle") }, layout: { x: _getFloat("layoutX"), y: _getFloat("layoutY"), width: _getFloat("layoutWidth"), height: _getFloat("layoutHeight") } }); } function getActiveChart(sheet) { let activeChart = null; sheet.charts.all().forEach(function (chart) { if (chart.isSelected()) { activeChart = chart; } }); return activeChart; } function _getElementById(id) { return document.getElementById(id); } function _geBoolean(id) { return _getElementById(id).checked; } function _getFloat(id) { const value = parseFloat(_getElementById(id).value); return isNaN(value) ? undefined : value; } function _getValue(id) { return parseInt(_getElementById(id).value); } function _getText(id) { return _getElementById(id).value; } function _setInputValue(id, value) { _getElementById(id).value = value === undefined ? "" : value; } function normalizeColor(color, defaultColor) { if (!color) { return defaultColor; } if (typeof color !== "string") { return defaultColor; } if (/^#[0-9a-f]{6}$/i.test(color)) { return color; } if (/^#[0-9a-f]{3}$/i.test(color)) { return "#" + color.slice(1).split("").map(function (value) { return value + value; }).join(""); } const rgbMatch = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*[\d.]+)?\)$/i); if (rgbMatch) { return "#" + toHex(rgbMatch[1]) + toHex(rgbMatch[2]) + toHex(rgbMatch[3]); } const context = document.createElement("canvas").getContext("2d"); context.fillStyle = defaultColor; context.fillStyle = color; return /^#[0-9a-f]{6}$/i.test(context.fillStyle) ? context.fillStyle : defaultColor; } function toHex(value) { const hex = parseInt(value, 10).toString(16); return hex.length === 1 ? "0" + hex : hex; }
<!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" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css" /> <script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-shapes/dist/gc.spread.sheets.shapes.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets-charts/dist/gc.spread.sheets.charts.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.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 class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <p>Change the properties below then press the Set button to apply these changes.</p> <div class="option-row" id=""> <label for="backColor">Back Color</label> <input type="color" id="backColor" value="#FF0000" /> </div> <div class="option-row" id=""> <label for="backColorTransparency">Back Color Transparency</label> <input type="number" id="backColorTransparency" step="0.1" min="0" max="1" value="0.7" /> </div> <hr> <div class="option-row"> <label for="layoutX">Plot Area X(% of Chart)</label> <input type="number" id="layoutX" step="0.01" min="0" max="1" /> </div> <div class="option-row"> <label for="layoutY">Plot Area Y(% of Chart)</label> <input type="number" id="layoutY" step="0.01" min="0" max="1" /> </div> <div class="option-row"> <label for="layoutWidth">Plot Area Width(% of Chart)</label> <input type="number" id="layoutWidth" step="0.01" min="0" max="1" /> </div> <div class="option-row"> <label for="layoutHeight">Plot Area Height(% of Chart)</label> <input type="number" id="layoutHeight" step="0.01" min="0" max="1" /> </div> <hr> <div class="option-row" id=""> <label for="border-color">Border Color:</label> <input type="color" id="border-color" value="#00FF00" /> </div> <div class="option-row" id=""> <label for="border-transparency">Border Transparency:</label> <input type="number" id="border-transparency" step="0.1" min="0" max="1" value="1" /> </div> <div class="option-row" id=""> <label for="border-width">Border Width:</label> <input type="number" id="border-width" step="1" min="0" max="100" value="1" /> </div> <div class="option-row" id=""> <label for="border-dashStyle">Border DashStyle:</label> <select id="border-dashStyle"> <option value="0" selected="selected">solid</option> <option value="1">dot</option> <option value="2">dash</option> <option value="3">lgDash</option> <option value="4">dashDot</option> <option value="5">lgDashDot</option> <option value="6">lgDashDotDot</option> <option value="7">sysDash</option> <option value="8">sysDot</option> <option value="9">sysDashDot</option> <option value="10">sysDashDotDot</option> </select> </div> <div class="option-row"> <input type="button" id="apply" value="Set" /> </div> </div> </div> </div> </body> </html>
.sample-tutorial { position: relative; display: flex; width: 100%; height: 100%; overflow: hidden; background: #f5f7fb; font-family: "Segoe UI", Arial, sans-serif; } .sample-spreadsheets { flex: 1 1 auto; min-width: 0; height: 100%; overflow: hidden; } .options-container { flex: 0 0 300px; width: 300px; padding: 18px 16px; height: 100%; box-sizing: border-box; background: #ffffff; border-left: 1px solid #d9e1ee; box-shadow: -8px 0 24px rgba(32, 45, 64, 0.08); color: #27313f; overflow: auto; } .options-container p { margin: 0 0 18px; padding: 12px 14px; border: 1px solid #e1e8f2; border-radius: 8px; background: #f8fbff; color: #526173; font-size: 13px; line-height: 1.5; } .option-row { margin-bottom: 14px; font-size: 14px; } .option-row:last-child { margin-top: 20px; margin-bottom: 0; } .option-row label { display: block; margin-bottom: 6px; color: #344154; font-size: 13px; font-weight: 600; } .option-row input, .option-row select { box-sizing: border-box; width: 100%; height: 34px; padding: 6px 10px; border: 1px solid #cfd8e6; border-radius: 6px; background: #ffffff; color: #1f2937; font: inherit; transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease; } .option-row input:hover, .option-row select:hover { border-color: #9db2ce; } .option-row input:focus, .option-row select:focus { border-color: #2f73d8; box-shadow: 0 0 0 3px rgba(47, 115, 216, 0.16); outline: none; } input[type="checkbox"] { display: inline-block; width: auto; } input[type="button"] { height: 38px; border: 0; border-radius: 6px; background: #2f73d8; color: #ffffff; font-weight: 600; cursor: pointer; box-shadow: 0 8px 18px rgba(47, 115, 216, 0.24); } input[type="button"]:hover { background: #235fb7; } input[type="button"]:active { background: #1d519d; box-shadow: none; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0; }