수식에서 다음과 같이 MonthSparkline 함수를 사용하여 월 스파크라인을 만들 수 있습니다. =MONTHSPARKLINE(year, month, dataRange, emptyColor, startColor, middleColor, endColor). 또는 =MONTHSPARKLINE(year, month, dataRange, colorRange).
이 함수에는 다음과 같은 매개 변수가 있습니다.
year: 전체 연도 숫자입니다(예: 2015).
month: 월 숫자입니다(예: 3).
dataRange: 이 참조는 첫 번째 열이 날짜이고 두 번째 열이 숫자인 범위를 나타냅니다(예: 'A1:B400').
emptyColor: 이 색 문자열은 값이 없거나 0 값을 가진 요일을 나타냅니다(예: 'lightgray').
startColor: 이 색 문자열은 값이 최소값인 요일을 나타냅니다(예: 'lightgreen').
middleColor: 이 색 문자열은 값이 최소값과 최대값의 평균인 날짜를 나타냅니다(예: 'green').
endColor: 이 색 문자열은 값이 최소값인 요일을 나타냅니다(예: 'darkgreen').
colorRange: 이 참조는 데이터가 색 문자열인 범위를 나타냅니다.
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
initNormalSheet(spread);
initColorRangeSheet(spread);
};
function initNormalSheet(spread) {
var sheet = spread.sheets[0];
sheet.name("No ColorRange");
sheet.suspendPaint();
sheet.setColumnWidth(0, 80);
sheet.setColumnWidth(1, 60);
sheet.setColumnWidth(2, 30);
sheet.setColumnWidth(3, 80);
sheet.setColumnWidth(4, 60);
sheet.setColumnWidth(5, 30);
sheet.setColumnWidth(6, 90);
sheet.getRange(0,0,1,7).backColor("#999999").foreColor("#FFFFFF");
sheet.setFormatter(-1, 0, "yyyy-MM-dd");
sheet.setFormatter(-1, 3, "yyyy-MM-dd");
sheet.addSpan(2, 6, 5, 1);
sheet.addSpan(9, 6, 5, 1);
var currentYear = new Date().getFullYear();
for (let row = 1; row <= 31; row++) {
sheet.setValue(row, 0, new Date(currentYear, 0, row));
sheet.setValue(row, 1, Math.round(Math.random() * 100));
}
for (let row = 1; row <= 28; row++) {
sheet.setValue(row, 3, new Date(currentYear, 1, row));
sheet.setValue(row, 4, Math.round(Math.random() * 100));
}
sheet.setText(0,0,"January");
sheet.setText(0,1,"Value");
sheet.setText(0,3,"February");
sheet.setText(0,4,"Value");
sheet.setText(0,6,"Diagram");
sheet.setFormula(2, 6, '=MONTHSPARKLINE('+currentYear+', 1, A2:B32, "#6d6d6d", "#c4c4c4", "#979797", "#f3f3f3")');
sheet.setFormula(7, 6, '=TEXT(DATE('+currentYear+',1, 1),"mmmm")');
sheet.setFormula(9, 6, '=MONTHSPARKLINE('+currentYear+',2,D2:E29, "#6d6d6d", "#c4c4c4", "#979797", "#f3f3f3")');
sheet.setFormula(14, 6, '=TEXT(DATE('+currentYear+',2, 1),"mmmm")');
sheet.resumePaint();
}
function initColorRangeSheet(spread) {
var sheet = spread.sheets[1];
sheet.name("ColorRange");
sheet.suspendPaint();
sheet.setColumnWidth(0, 80);
sheet.setColumnWidth(1, 70);
sheet.setColumnWidth(2, 70);
sheet.setColumnWidth(3, 30);
sheet.setColumnWidth(4, 80);
sheet.setColumnWidth(5, 70);
sheet.setColumnWidth(6, 70);
sheet.setColumnWidth(7, 30);
sheet.setColumnWidth(8, 90);
sheet.getRange(0,0,1,9).backColor("#999999").foreColor("#FFFFFF");
sheet.setFormatter(-1, 0, "yyyy-MM-dd");
sheet.setFormatter(-1, 4, "yyyy-MM-dd");
sheet.addSpan(2, 8,5 , 1);
sheet.addSpan(9, 8, 5, 1);
var currentYear = new Date().getFullYear();
for (let row = 1; row < 29; row++) {
sheet.setValue(row, 0, new Date(currentYear, 0, row ));
sheet.setValue(row, 1, Math.round(Math.random() * 100));
sheet.setValue(row, 2, this.getRandomColor());
}
for (let row = 1; row < 29; row++) {
sheet.setValue(row, 4, new Date(currentYear, 1, row ));
sheet.setValue(row, 5, Math.round(Math.random() * 100));
sheet.setValue(row, 6, this.getRandomColor());
}
sheet.setText(0,0,"January");
sheet.setText(0,1,"Value");
sheet.setText(0,2,"Color");
sheet.setText(0,4,"February");
sheet.setText(0,5,"Value");
sheet.setText(0,6,"Color");
sheet.setText(0,8,"Diagram");
sheet.setFormula(2, 8, '=MONTHSPARKLINE('+currentYear+',1,A2:B31,C2:C32)');
sheet.setFormula(7, 8, '=TEXT(DATE('+currentYear+',1, 1),"mmmm")');
sheet.setFormula(9, 8, '=MONTHSPARKLINE('+currentYear+',2,E2:F29,G2:G29)');
sheet.setFormula(14, 8, '=TEXT(DATE('+currentYear+',2, 1),"mmmm")');
sheet.resumePaint();
}
function getRandomColor() {
var colorList = ["#82bc00", "#9fc94c", "#00C2D6", "#d2e4a7", "#e9f2d2", "#ffedd3", "#ffdba8", "#ffc97d", "#feb850", "#f7a711","#00c2d6"];
return colorList[Math.round(Math.random() * 10)];
}
<!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" style="width:100%;height:100%"></div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}