You can create a Year sparkline using the YearSparkline function in a formula: =YEARSPARKLINE(year, dataRange, emptyColor, startColor, middleColor, endColor)*. OR *=YEARSPARKLINE(year, dataRange, colorRange).
The function has the following parameters:
year : The full year number, such as 2015.
dataRange : The reference represents a range where the first column is date and the second column is number, such as 'A1:B400'.
emptyColor : The color string represents the days that have no value or zero value, such as 'lightgray'.
startColor : The color string represents the day where the value is the minimum value, such as 'lightgreen'.
middleColor : The color string represents the day where the value is the average of the minimum and maximum, such as 'green'.
endColor : The color string represents the day where the value is the maximum value, such as 'darkgreen'.
colorRange : The reference represents a range where the data is a color string.
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.setFormatter(-1, 0, "yyyy-MM-dd");
sheet.setColumnWidth(0, 80);
sheet.setColumnWidth(1, 60);
sheet.setColumnWidth(3, 600);
sheet.addSpan(2, 3, 4, 1);
sheet.setRowCount(366);
var rowCount = sheet.getRowCount();
sheet.setText(0,0,"Date");
sheet.setText(0,1,"Value");
sheet.setText(0,3,"Diagram");
var currentYear = new Date().getFullYear();
for (var row = 1; row < rowCount; row++) {
sheet.setValue(row, 0, new Date(currentYear, 0, row + 1));
sheet.setValue(row, 1, Math.round(Math.random() * 100));
}
sheet.getRange(0,0,366,4).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.getRange(0,0,1,4).backColor("#999999").foreColor("#FFFFFF");
//year sparkline
sheet.setFormula(2, 3, '=YearSparkline('+currentYear+', A2:B' + rowCount + ', "#6d6d6d", "#c4c4c4", "#979797", "#f3f3f3")');
sheet.resumePaint();
}
function initColorRangeSheet(spread) {
var sheet = spread.sheets[1];
sheet.name("ColorRange");
sheet.suspendPaint();
sheet.setFormatter(-1, 0, "yyyy-MM-dd");
sheet.setColumnWidth(0, 80);
sheet.setColumnWidth(1, 60);
sheet.setColumnWidth(3, 600);
sheet.setRowCount(366);
var rowCount = sheet.getRowCount();
sheet.setText(0,0,"Date");
sheet.setText(0,1,"Value");
sheet.setText(0,2,"Color");
sheet.setText(0,3,"Diagram");
sheet.addSpan(2, 3, 4, 1);
var rowCount = sheet.getRowCount();
var currentYear = new Date().getFullYear();
var colorList = ["#82bc00", "#9fc94c", "#00C2D6", "#d2e4a7", "#e9f2d2", "#ffedd3", "#ffdba8", "#ffc97d", "#feb850", "#f7a711","#00c2d6"];
for (var row = 1; row < rowCount; row++) {
sheet.setValue(row, 0, new Date(currentYear, 0, row + 1));
sheet.setValue(row, 1, Math.round(Math.random() * 100));
sheet.setValue(row, 2, colorList[Math.round(Math.random() * 10)])
}
sheet.getRange(0,0,366,4).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.getRange(0,0,1,4).backColor("#999999").foreColor("#FFFFFF");
//year sparkline
sheet.setFormula(2, 3, '=YearSparkline('+currentYear+', A2:B' + rowCount + ', C2:C366)');
sheet.resumePaint();
}
<!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$/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;
}