Last active
May 30, 2016 13:50
-
-
Save alexanderjeurissen/877d479143218c135113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateAlphaNumericLabels(amount) { | |
var labels = []; | |
for (var i = 0; i <= amount; i++) { | |
var appendNumber = 0; | |
var offset = 0; | |
if (i > 25 && i <= 34) { | |
appendNumber = i - 25; | |
labels.push(String.fromCharCode(65 + offset) + appendNumber); | |
} else if (i > 33) { | |
offset = Math.floor((i - 26) / 10); | |
appendNumber = i - (25 + (offset * 10)); | |
labels.push(String.fromCharCode(65 + offset) + appendNumber); | |
} else { | |
labels.push(String.fromCharCode(65 + i)); | |
} | |
} | |
return labels; | |
} |
If you wish to change it to the headers on excel documents for example, like continuous headers ["A",..."Z","A1",..."Z1","A2" ...] is really simple the change
function generateAlphaNumericLabels(amount) {
var labels = [];
for (var i = 0; i <= amount; i++) {
if (i > 25) {
labels.push(String.fromCharCode(65 + (i % 26)) + Math.floor(i/26));
} else {
labels.push(String.fromCharCode(65 + i));
}
}
return labels;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
returns an array of strings / labels that can be used for charts. The format of the returned list is:
the amount parameter determines how many elements will be generated. there is no check on the amount so in case the amount exceeds "Z10" you'll get strange labels with symbols in it.