From ede22c8ccc51634c8cef048a3f4e0f8b7c1f36b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=B6ger?= Date: Wed, 3 Jul 2013 18:59:37 +0200 Subject: [PATCH 1/2] Thousand Separator --- Chart.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Chart.js b/Chart.js index ffbe16f3711..85018b7514a 100755 --- a/Chart.js +++ b/Chart.js @@ -929,7 +929,7 @@ window.Chart = function(context){ ctx.stroke(); if (config.scaleShowLabels){ - ctx.fillText(calculatedScale.labels[j],yAxisPosX-8,xAxisPosY - ((j+1) * scaleHop)); + ctx.fillText(thousand_separator(calculatedScale.labels[j]),yAxisPosX-8,xAxisPosY - ((j+1) * scaleHop)); } } @@ -1421,6 +1421,24 @@ window.Chart = function(context){ // Provide some basic currying to the user return data ? fn( data ) : fn; }; + + function thousand_separator(input) { + var number = input.split('.'); + num = number[0]; + num = num.split("").reverse().join(""); + var numpoint = ''; + for (var i = 0; i < num.length; i++) { + numpoint += num.substr(i,1); + if (((i+1)%3 == 0) && i != num.length-1) { + numpoint += ','; + } + } + num = numpoint.split("").reverse().join(""); + if (number[1] != undefined) { + num = num+'.'+number[1]; + } + return num; + } } From 80ac8123cb5929a084bd5dbf68114a9fe6a751f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=B6ger?= Date: Sat, 13 Jul 2013 19:42:36 +0200 Subject: [PATCH 2/2] Correct label position line&bar --- Chart.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Chart.js b/Chart.js index 85018b7514a..297ebbc5267 100755 --- a/Chart.js +++ b/Chart.js @@ -879,14 +879,14 @@ window.Chart = function(context){ for (var i=0; i 0){ - ctx.translate(yAxisPosX + i*valueHop,xAxisPosY + config.scaleFontSize); + ctx.translate(yAxisPosX + i*valueHop + valueHop/2,xAxisPosY + config.scaleFontSize); ctx.rotate(-(rotateLabels * (Math.PI/180))); ctx.fillText(data.labels[i], 0,0); ctx.restore(); } - + else{ - ctx.fillText(data.labels[i], yAxisPosX + i*valueHop,xAxisPosY + config.scaleFontSize+3); + ctx.fillText(data.labels[i], yAxisPosX + i*valueHop + valueHop/2,xAxisPosY + config.scaleFontSize+3); } ctx.beginPath(); @@ -1087,12 +1087,12 @@ window.Chart = function(context){ for (var i=0; i 0){ - ctx.translate(yAxisPosX + i*valueHop,xAxisPosY + config.scaleFontSize); + ctx.translate(yAxisPosX + i*valueHop + valueHop/2,xAxisPosY + config.scaleFontSize); ctx.rotate(-(rotateLabels * (Math.PI/180))); ctx.fillText(data.labels[i], 0,0); ctx.restore(); } - + else{ ctx.fillText(data.labels[i], yAxisPosX + i*valueHop + valueHop/2,xAxisPosY + config.scaleFontSize+3); }