-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from FVANCOP/issue502
Issue502
- Loading branch information
Showing
2 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<!doctype html> | ||
<meta http-equiv="content-type" content="text/html; charset=windows-1250"> | ||
|
||
<!--[if lte IE 8]><SCRIPT src='source/excanvas.js'></script><![endif]--> | ||
<SCRIPT src='../ChartNew.js'></script> | ||
<SCRIPT src='../Add-ins/shapesInChart.js'></script> | ||
|
||
|
||
<SCRIPT> | ||
|
||
|
||
|
||
var charJSPersonnalDefaultOptions = { decimalSeparator : "," , thousandSeparator : ".", roundNumber : "none", graphTitleFontSize: 2 }; | ||
|
||
defCanvasWidth=1200; | ||
defCanvasHeight=600; | ||
|
||
var mydata1 = { | ||
labels : ["2015","2016"], | ||
datasets : [ | ||
{ | ||
data : [0,10], | ||
fillColor : "rgba(220,0,220,0.2)", | ||
title : "data1", | ||
}, | ||
{ | ||
data : [10,0], | ||
fillColor : "rgba(220,0,220,0.2)", | ||
title : "data2", | ||
}, | ||
{ | ||
data : [90,0], | ||
fillColor : "rgba(0,0,220,0.2)", | ||
title : "label for data3", | ||
}, | ||
{ | ||
data : [0,50], | ||
fillColor : "rgba(220,0,220,0.2)", | ||
title : "data4", | ||
}, | ||
{ | ||
data : [10,10], | ||
fillColor : "rgba(220,0,220,0.2)", | ||
title : "data5", | ||
}, | ||
{ | ||
data : [24,80], | ||
fillColor : "rgba(220,0,0,0.2)", | ||
title : "data6", | ||
}, | ||
{ | ||
data : [58,20], | ||
fillColor : "rgba(0,220,220,0.2)", | ||
title : "data7", | ||
}, | ||
{ | ||
data : [18,0], | ||
fillColor : "rgba(0,220,0,0.2)", | ||
title : "data8", | ||
}, | ||
{ | ||
data : [8,25], | ||
fillColor : "rgba(50,100,150,0.2)", | ||
title : "data9", | ||
} | ||
] | ||
}; | ||
|
||
var opt1 = { | ||
endDrawDataFunction: drawShapes | ||
}; | ||
|
||
|
||
|
||
// add text around; | ||
|
||
function setXPos(typVal,i,j,k,txt,startAngle,endAngle,fontSize,position,truncLabel,inradius,outradius) { | ||
|
||
var nbcharRound=(inradius+position*(outradius-inradius))*2*Math.PI/(fontSize/2); | ||
var degPerChar=Math.ceil(10*360/nbcharRound)/10; | ||
var availableAngle=(180/Math.PI)*(endAngle-startAngle); | ||
var newText=txt; | ||
if(availableAngle<degPerChar*txt.length){ | ||
if(truncLabel==false) { | ||
if (typVal=="TEXT")return(""); | ||
else return(i); | ||
} else { | ||
newText=txt.substring(0,Math.floor(availableAngle/degPerChar)); | ||
if(k>=newText.length) { | ||
if (typVal=="TEXT")return(""); | ||
else return(i); | ||
} | ||
} | ||
} | ||
if(typVal=="TEXT")return(txt.substring(k,k+1)); | ||
var addAngle=(availableAngle-degPerChar*newText.length)/2+k*degPerChar+degPerChar/2; | ||
if(typVal=="X1") return(i-0.5+addAngle/availableAngle); | ||
if(typVal=="ROTATE")return ((180/Math.PI)*(startAngle)+addAngle+90); | ||
} ; | ||
|
||
function addRoundText(data,fontSize,position,truncLabel) { | ||
if(typeof data.shapesInChart!=="object")data.shapesInChart=[]; | ||
for(i=0;i<data.datasets.length;i++) { | ||
for(j=0;j<data.labels.length;j++) { | ||
tt=typeof (1*data.datasets[i].data[j]) ; | ||
if(tt!="number")continue; | ||
for(k=0;k<data.datasets[i].title.length;k++){ | ||
data.shapesInChart[data.shapesInChart.length]={ | ||
shape: "TEXT", | ||
iter : "last", | ||
text: "%eval(setXPos('TEXT',"+i+","+j+","+k+",'"+data.datasets[i].title+"',statData["+i+"]["+j+"].startAngle,statData["+i+"]["+j+"].endAngle,"+fontSize+","+position+","+truncLabel+",statData["+i+"]["+j+"].inRadius,statData["+i+"]["+j+"].outRadius);", | ||
fontSize : fontSize, | ||
textAlign : "center", | ||
textBaseline : "bottom", | ||
fontColor : "black", | ||
animate : false, | ||
x1: "%eval(setXPos('X1',"+i+","+j+","+k+",'"+data.datasets[i].title+"',statData["+i+"]["+j+"].startAngle,statData["+i+"]["+j+"].endAngle,"+fontSize+","+position+","+truncLabel+",statData["+i+"]["+j+"].inRadius,statData["+i+"]["+j+"].outRadius);", | ||
y1: position, | ||
posj: j, | ||
rotate: "%eval(setXPos('ROTATE',"+i+","+j+","+k+",'"+data.datasets[i].title+"',statData["+i+"]["+j+"].startAngle,statData["+i+"]["+j+"].endAngle,"+fontSize+","+position+","+truncLabel+",statData["+i+"]["+j+"].inRadius,statData["+i+"]["+j+"].outRadius);", | ||
paddingX1 : 0, | ||
paddingY1 : 0 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
|
||
|
||
var truncLabel=false; // -> true or false; | ||
position=0.70; // -> value between 0 and 1; | ||
|
||
addRoundText(mydata1,30,position,truncLabel); | ||
|
||
|
||
</SCRIPT> | ||
|
||
|
||
<html> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> | ||
<head> | ||
<title>Demo ChartNew.js</title> | ||
</head> | ||
<body> | ||
|
||
<center> | ||
<FONT SIZE=6><B>Demo of ChartNew.js !</B></FONT> <BR> | ||
|
||
<script> | ||
|
||
document.write("<canvas id=\"canvas_Line\" height=\""+defCanvasHeight+"\" width=\""+defCanvasWidth+"\"></canvas>"); | ||
window.onload = function() { | ||
var myLine = new Chart(document.getElementById("canvas_Line").getContext("2d")).Pie(mydata1,opt1); | ||
} | ||
</script> | ||
</body> | ||
</html> |