groupSparkline 및 ungroupSparkline 메서드를 사용하여 스파크라인을 그룹화하고 그룹 해제할 수 있습니다. 예:
sparklineType 메서드를 사용하여 스파크라인의 유형을 변경할 수 있습니다. 예:
또한 데이터 및 dataAxisData 메서드를 가져오고 설정할 수 있습니다. data 메서드를 사용하여 데이터 개체를 가져오고 설정합니다. dataOrientation 메서드를 사용하여 데이터 방향을 가져오고 설정합니다. dateAxisData 메서드를 사용하여 날짜 축 데이터 개체를 가져오고 설정합니다. dateAxisOrientation 메서드를 사용하여 날짜 축 방향을 가져오고 설정합니다. displayDateAxis 메서드를 사용하여 날짜 축 표시 여부를 가져오고 설정합니다. 예:
많은 스파크라인 설정이 있습니다. setting 메서드를 사용하여 스파크라인 설정을 가져오고 설정할 수 있습니다. 예:
여러 스파크라인이 그룹화되면 해당 스파크라인은 동일한 설정을 공유합니다. 다음 단계에서 설정에 대한 자세한 내용을 보게 됩니다.
스파크라인에 대한 이벤트가 있습니다. 스파크라인이 변경되면 발생합니다. 예:
var spreadNS = GC.Spread.Sheets;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
initSpread(spread);
};
function initSpread(spread) {
var sheet = spread.getSheet(0);
sheet.suspendPaint();
sheet.options.allowCellOverflow = true;
var data = [1,-2,-1,6,4,-4,3,8];
var dateAxis = [new Date(2011, 0, 5),new Date(2011, 0, 1),new Date(2011, 1, 11),new Date(2011, 2, 1),
new Date(2011, 1, 1),new Date(2011, 1, 3),new Date(2011, 2, 6),new Date(2011, 1, 19)];
sheet.setValue(0, 0, "Series 1");
sheet.setValue(0, 1, "Series 2");
for(let i=0;i<8;i++)
{
sheet.setValue(i+1, 0,data[i]);
sheet.getCell(i+1, 1).value(dateAxis[i]).formatter("yyyy-mm-dd");
}
sheet.setColumnWidth(1,100);
sheet.setValue(10, 0, "*Data Range is A2-A9");
sheet.setValue(11, 0, "*Date axis range is B2-B9");
var dataRange = new spreadNS.Range(1, 0, 8, 1);
var dateAxisRange = new spreadNS.Range(1, 1, 8, 1);
sheet.getCell(13, 0).text("Sparkline with dateAxis:");
sheet.getCell(14, 0).text("(1) Line");
sheet.getCell(14, 3).text("(2)Column");
sheet.getCell(14, 6).text("(3)Winloss");
//line
sheet.addSpan(15, 0, 4, 3);
var setting = new spreadNS.Sparklines.SparklineSetting();
setting.options.showMarkers = true;
setting.options.displayXAxis = true;
setting.options.showFirst = true;
setting.options.showLast = true;
setting.options.showLow = true;
setting.options.showHigh = true;
setting.options.showNegative = true;
sheet.setSparkline(15, 0, dataRange
, spreadNS.Sparklines.DataOrientation.vertical
, spreadNS.Sparklines.SparklineType.line
, setting
, dateAxisRange
, spreadNS.Sparklines.DataOrientation.vertical
);
//column
sheet.addSpan(15, 3, 4, 3);
setting = new spreadNS.Sparklines.SparklineSetting();
setting.options.displayXAxis = true;
setting.options.showFirst = true;
setting.options.showLast = true;
setting.options.showLow = true;
setting.options.showHigh = true;
setting.options.showNegative = true;
sheet.setSparkline(15, 3, dataRange
, spreadNS.Sparklines.DataOrientation.vertical
, spreadNS.Sparklines.SparklineType.column
, setting
, dateAxisRange
, spreadNS.Sparklines.DataOrientation.vertical
);
//winloss
sheet.addSpan(15, 6, 4, 3);
setting = new spreadNS.Sparklines.SparklineSetting();
setting.options.displayXAxis = true;
setting.options.showNegative = true;
sheet.setSparkline(15, 6, dataRange
, spreadNS.Sparklines.DataOrientation.vertical
, spreadNS.Sparklines.SparklineType.winloss
, setting
, dateAxisRange
, spreadNS.Sparklines.DataOrientation.vertical
);
sheet.bind(spreadNS.Events.SelectionChanged, selectionChangedCallback);
sheet.resumePaint();
function selectionChangedCallback() {
var sheet = spread.getActiveSheet();
var sparkline = sheet.getSparkline(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex());
if (sparkline) {
updateSetting(sparkline);
} else {
initSetting();
}
}
function updateSetting(sparkline) {
var type = sparkline.sparklineType(), displayDateAxis = sparkline.displayDateAxis();
var sparklinetype = _getElementById("sparklinetype");
_selectOption(sparklinetype, type + "");
_getElementById("displayDateAxis").setAttribute("checked", !!displayDateAxis);
}
function initSetting() {
var sparklinetype = _getElementById("sparklinetype");
_selectOption(sparklinetype, '0');
_getElementById("displayDateAxis").setAttribute("checked", false);
}
function getActualRange(range, maxRowCount, maxColCount) {
var row = range.row < 0 ? 0 : range.row;
var col = range.col < 0 ? 0 : range.col;
var rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount;
var colCount = range.colCount < 0 ? maxColCount : range.colCount;
return new spreadNS.Range(row, col, rowCount, colCount);
}
_getElementById("btnGroupSparkline").addEventListener('click',function () {
var sheet = spread.getActiveSheet();
sheet.suspendPaint();
var sels = sheet.getSelections();
var i = 0;
var sparklines = [];
for (var n = 0; n < sels.length; n++) {
if (sels) {
var sel = getActualRange(sels[n], sheet.getRowCount(), sheet.getColumnCount());
var rowCount = sel.rowCount;
var colCount = sel.colCount;
for (var i = 0; i < rowCount; i++) {
for (var j = 0; j < colCount; j++) {
var sparkline = sheet.getSparkline(sel.row + i, sel.col + j);
if (sparkline != null) {
sparklines.push(sparkline);
}
}
}
sheet.groupSparkline(sparklines);
}
}
sheet.resumePaint();
});
_getElementById("btnUnGroupSparkline").addEventListener('click',function () {
var sheet = spread.getActiveSheet();
sheet.suspendPaint();
var sels = sheet.getSelections();
var sparkline;
for (var n = 0; n < sels.length; n++) {
if (sels) {
var sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount());
var rowCount = sel.rowCount;
var colCount = sel.colCount;
for (var i = 0; i < rowCount; i++) {
for (var j = 0; j < colCount; j++) {
sparkline = sheet.getSparkline(sel.row + i, sel.col + j);
if (sparkline != null) {
sheet.ungroupSparkline(sparkline.group());
}
}
}
}
}
sheet.resumePaint();
});
_getElementById("sparklinetype").addEventListener('change',function () {
var sheet = spread.getActiveSheet();
sheet.suspendPaint();
var sels = sheet.getSelections();
var sparkline;
for (var n = 0; n < sels.length; n++) {
if (sels) {
var sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount());
var rowCount = sel.rowCount;
var colCount = sel.colCount;
for (var i = 0; i < rowCount; i++) {
for (var j = 0; j < colCount; j++) {
sparkline = sheet.getSparkline(sel.row + i, sel.col + j);
if (sparkline != null) {
sparkline.sparklineType(parseInt(this.value));
}
}
}
}
}
sheet.resumePaint();
});
_getElementById("displayDateAxis").addEventListener('change',function () {
var sheet = spread.getActiveSheet();
sheet.suspendPaint();
var sels = sheet.getSelections();
var sparkline;
for (var n = 0; n < sels.length; n++) {
if (sels) {
var sel = getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount());
var rowCount = sel.rowCount;
var colCount = sel.colCount;
for (var i = 0; i < rowCount; i++) {
for (var j = 0; j < colCount; j++) {
sparkline = sheet.getSparkline(sel.row + i, sel.col + j);
if (sparkline != null) {
sparkline.displayDateAxis(this.checked);
}
}
}
}
}
sheet.resumePaint();
});
};
function _getElementById(id){
return document.getElementById(id);
}
function _selectOption(select, value) {
for (var i = 0; i < select.length; i++) {
var op = select.options[i];
if (op.value === value) {
op.selected = true;
} else {
op.selected = false;
}
}
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="ko-kr"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.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 id="ss" class="sample-spreadsheets"></div>
<div class="options-container">
<div class="option-group">
<label><b>Group and UnGroup SparkLines:</b></label>
</div>
<hr>
<div class="option-group">
<label>You can select multiple sparklines and group (or ungroup them).</label>
</div>
<div class="option-group">
<label>Group Sparklines</label>
</div>
<div class="option-group">
<input type="button" value="Group" id="btnGroupSparkline">
</div>
<div class="option-group">
<label>Un Group Sparklines</label>
</div>
<div class="option-group">
<input id='btnUnGroupSparkline' type='button' value='UnGroup' />
</div>
<br>
<div class="option-group">
<label>*The sparklines in a group have the same settings.
If you change the settings on one sparkline, the change is mirrored in all sparklines in that group.</label>
</div>
<div class="option-group">
<label><b>Change the Sparkline settings:</b></label>
</div>
<hr>
<div class="option-group">
<label for="sparklinetype">Type:</label>
<select id="sparklinetype">
<option value="0">line</option>
<option value="1">column</option>
<option value="2">winloss</option>
</select>
</div>
<div class="option-group">
<input type="checkbox" id="displayDateAxis" checked />
<label for="displayDateAxis">Display DateAxis</label>
</div>
</div>
</div>
</body>
</html>
.sample {
position: relative;
height: 100%;
overflow: auto;
}
.sample::after {
display: block;
content: "";
clear: both;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
.option-group {
margin-bottom: 12px;
}
input,
select {
padding: 4px 6px;
box-sizing: border-box;
}
p{
padding:2px 10px;
background-color:#F4F8EB;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}