Category: Javascript & Jquery & React & Angular
about javascript & jquery
-
statcked chart chart.js
<!DOCTYPE html><html lang=”en”><head><metacharset=”UTF-8″><metahttp-equiv=”X-UA-Compatible”content=”IE=edge”><metaname=”viewport”content=”width=device-width, initial-scale=1.0″><title>Document</title><scriptsrc=”https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js”></script></head><body><canvasid=”bar-chart”width=”600″height=”350″></canvas></body></html><script>varnumberWithCommas = function(x) {returnx.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);};var dataPack1 = [50000, 0, 0,0, 0, 0, 0, 0, 0, 0, 60100, 62000];var dataPack2 = [0, 6000, 13000, 14000, 50060, 20030, 20070, 35000, 41000, 4020, 40030, 70050];var dates = [“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”];// Chart.defaults.global.elements.rectangle.backgroundColor = ‘#FF0000’;var bar_ctx = document.getElementById(‘bar-chart’);var bar_chart = new Chart(bar_ctx, {type:’bar’,data: {labels:dates,datasets: [{label:’SoftEnterprises, Sales’,data:dataPack1,backgroundColor:”rgba(55, 160, 225, 0.7)”,hoverBackgroundColor:”rgba(55, 160, 225, 0.7)”,hoverBorderWidth:2,hoverBorderColor:’lightgrey’},{label:’SmartSystems, Sales’,data:dataPack2,backgroundColor:”rgba(225, 58, 55, 0.7)”,hoverBackgroundColor:”rgba(225, 58, 55, 0.7)”,hoverBorderWidth:2,hoverBorderColor:’lightgrey’},]},options: {animation: {duration:10,onComplete:function(){vararr = [800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800]varmodel_y, gapvarchartInstance = this.chart,ctx = chartInstance.ctx;ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);ctx.textAlign = ‘center’;ctx.textBaseline = ‘bottom’;ctx.fillStyle = ‘#000’;this.data.datasets.forEach(function(dataset, i) {varisHidden = dataset._meta[0].hidden; //’hidden’ property of datasetif (!isHidden) { //if dataset is not hiddenvarmeta = chartInstance.controller.getDatasetMeta(i);//console.log(‘meta’, meta)meta.data.forEach(function(bar, index) {vardata = dataset.data[index];diff = arr[index] – bar._model.yarr[index] = bar._model.ygap = diff / 2model_y = bar._model.y + gapconsole.log(‘i, index, model.y’, i, index, bar._model.y, arr[index])ctx.fillText(data, bar._model.x, model_y);});}});}},tooltips: {mode:’label’,callbacks: {label:function(tooltipItem, data) {returndata.datasets[tooltipItem.datasetIndex].label + “: ” + numberWithCommas(tooltipItem.yLabel);}}},scales: {xAxes: [{stacked:true,gridLines: { display:false },}],yAxes: [{stacked:true,ticks: {callback:function(value) { returnnumberWithCommas(value);},},}],}, // scaleslegend: {display:true}} // options},);</script> -
javascript find key from value
최신 브라우즈에서 value로 key 찾기 .
var key = Object.keys(obj).filter(function(key) {return obj[key] === value})[0];[jQuery] 특정 요소에 포커스 주고 빼기 feat. focus() and blur() – 모두의매뉴얼 (triki.net)
-
A Complete Guide to Stacked Bar Charts
A Complete Guide to Stacked Bar Charts
A Complete Guide to Stacked Bar Charts | Tutorial by Chartio
-
javascript 2 dimesion array definition
var myArray = new Array( new Array(), new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array() );
myArray[0][0] = 1;
myArray[0][1] = 43;
myArray[0][2] = 14;
myArray[0][3] = 34;
myArray[0][4] = 9;
myArray[0][5] = 5;
myArray[0][6] = 26;
myArray[0][7] = 11;myArray[1][0] = 10;
myArray[1][1] = 58;
myArray[1][2] = 38;
myArray[1][3] = 54;
myArray[1][4] = 61;
myArray[1][5] = 60;
myArray[1][6] = 41;
myArray[1][7] = 19;myArray[2][0] = 13;
myArray[2][1] = 49;
myArray[2][2] = 30;
myArray[2][3] = 55;
myArray[2][4] = 37;
myArray[2][5] = 63;
myArray[2][6] = 22;
myArray[2][7] = 36;myArray[3][0] = 25;
myArray[3][1] = 17;
myArray[3][2] = 21;
myArray[3][3] = 51;
myArray[3][4] = 42;
myArray[3][5] = 3;
myArray[3][6] = 27;
myArray[3][7] = 24;myArray[4][0] = 44;
myArray[4][1] = 28;
myArray[4][2] = 50;
myArray[4][3] = 32;
myArray[4][4] = 57;
myArray[4][5] = 48;
myArray[4][6] = 18;
myArray[4][7] = 46;myArray[5][0] = 6;
myArray[5][1] = 47;
myArray[5][2] = 64;
myArray[5][3] = 40;
myArray[5][4] = 59;
myArray[5][5] = 29;
myArray[5][6] = 4;
myArray[5][7] = 7;myArray[6][0] = 33;
myArray[6][1] = 31;
myArray[6][2] = 56;
myArray[6][3] = 62;
myArray[6][4] = 53;
myArray[6][5] = 39;
myArray[6][6] = 52;
myArray[6][7] = 15;myArray[7][0] = 12;
myArray[7][1] = 45;
myArray[7][2] = 35;
myArray[7][3] = 16;
myArray[7][4] = 20;
myArray[7][5] = 8;
myArray[7][6] = 23;
myArray[7][7] = 2;for (i = 0; i < myArray.length ;i++ )
{
var s = 0;
var n = 0;
for (j = 0; j < myArray[i].length ;j++ )
{
document.write(myArray[i][j]) ;
s = s + myArray[i][j];
n = n + myArray[j][i];}
document.write(” : ” + n );
document.write(” = ” + s +”<br>”);}
-
Custom File Input Smart way
<script>function setfilename(val){var fileName = val.substr(val.lastIndexOf(“\\”)+1, val.length);document.getElementById(“filename”).value = fileName;}</script><form>File: <input type=”file” id=”file” name=”file” onchange=”setfilename(this.value);”/>Upload File : <input type=”text” id=”filename”/></form>