Created
November 22, 2014 03:48
-
-
Save tudo75/502dd77a020516c0d77c to your computer and use it in GitHub Desktop.
Chart.js Demo // source http://jsbin.com/bikoqe
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Chart.js Demo</title> | |
<style id="jsbin-css"> | |
img { | |
border: 1px dashed red; | |
margin-top: 20px; | |
} | |
br { | |
clear: both; | |
} | |
.pie-legend | |
{ | |
padding-left: 0; | |
list-style: none; | |
} | |
.pie-legend li | |
{ | |
display: block; | |
position: relative; | |
margin-bottom: 4px; | |
padding: 2px 8px 2px 18px; | |
cursor: default; | |
} | |
.pie-legend li span | |
{ | |
display: block; | |
position: absolute; | |
left: 0; | |
top: 0; | |
width: 12px; | |
height: 100%; | |
} | |
#legend { | |
float: right; | |
width: 100px; | |
} | |
#canvas-container { | |
float: left; | |
width: 350px; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<div id="canvas-container"> | |
<canvas id="canvas"></canvas> | |
</div> | |
<div id="legend"></div> | |
</div> | |
<br/> | |
<img id="url" /> | |
<script src="https://raw.github.com/nnnick/Chart.js/master/Chart.js"></script> | |
<script id="jsbin-javascript"> | |
var data = [ | |
{ | |
value: 300, | |
color:"#F7464A", | |
highlight: "#FF5A5E", | |
label: "Red" | |
}, | |
{ | |
value: 50, | |
color: "#46BFBD", | |
highlight: "#5AD3D1", | |
label: "Green" | |
}, | |
{ | |
value: 100, | |
color: "#FDB45C", | |
highlight: "#FFC870", | |
label: "Yellow" | |
} | |
]; | |
var ctx = document.getElementById("canvas").getContext("2d"); | |
var pieChart = new Chart(ctx).Pie(data, { | |
animateRotate : false, | |
animateScale: false, | |
responsive: true, | |
tooltipCornerRadius: 0, | |
onAnimationComplete: function(){ | |
document.getElementById("url").src = pieChart.toBase64Image(); | |
} | |
}); | |
var helpers = Chart.helpers; | |
var canvas = document.getElementById("canvas"); | |
var legendHolder = document.getElementById("legend"); | |
legendHolder.innerHTML = pieChart.generateLegend(); | |
helpers.each(legendHolder.firstChild.childNodes, function(legendNode, index){ | |
helpers.addEvent(legendNode, 'mouseover', function(){ | |
var activeSegment = pieChart.segments[index]; | |
legendNode.style.backgroundColor = activeSegment.fillColor; | |
activeSegment.save(); | |
activeSegment.fillColor = activeSegment.highlightColor; | |
pieChart.showTooltip([activeSegment]); | |
activeSegment.restore(); | |
}); | |
helpers.addEvent(legendNode, 'mouseout', function(){ | |
var activeSegment = pieChart.segments[index]; | |
legendNode.style.backgroundColor = "transparent"; | |
}); | |
}); | |
helpers.addEvent(legendHolder.firstChild, 'mouseout', function(){ | |
pieChart.draw(); | |
}); | |
</script> | |
<script id="jsbin-source-css" type="text/css">img { | |
border: 1px dashed red; | |
margin-top: 20px; | |
} | |
br { | |
clear: both; | |
} | |
.pie-legend | |
{ | |
padding-left: 0; | |
list-style: none; | |
} | |
.pie-legend li | |
{ | |
display: block; | |
position: relative; | |
margin-bottom: 4px; | |
padding: 2px 8px 2px 18px; | |
cursor: default; | |
} | |
.pie-legend li span | |
{ | |
display: block; | |
position: absolute; | |
left: 0; | |
top: 0; | |
width: 12px; | |
height: 100%; | |
} | |
#legend { | |
float: right; | |
width: 100px; | |
} | |
#canvas-container { | |
float: left; | |
width: 350px; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var data = [ | |
{ | |
value: 300, | |
color:"#F7464A", | |
highlight: "#FF5A5E", | |
label: "Red" | |
}, | |
{ | |
value: 50, | |
color: "#46BFBD", | |
highlight: "#5AD3D1", | |
label: "Green" | |
}, | |
{ | |
value: 100, | |
color: "#FDB45C", | |
highlight: "#FFC870", | |
label: "Yellow" | |
} | |
]; | |
var ctx = document.getElementById("canvas").getContext("2d"); | |
var pieChart = new Chart(ctx).Pie(data, { | |
animateRotate : false, | |
animateScale: false, | |
responsive: true, | |
tooltipCornerRadius: 0, | |
onAnimationComplete: function(){ | |
document.getElementById("url").src = pieChart.toBase64Image(); | |
} | |
}); | |
var helpers = Chart.helpers; | |
var canvas = document.getElementById("canvas"); | |
var legendHolder = document.getElementById("legend"); | |
legendHolder.innerHTML = pieChart.generateLegend(); | |
helpers.each(legendHolder.firstChild.childNodes, function(legendNode, index){ | |
helpers.addEvent(legendNode, 'mouseover', function(){ | |
var activeSegment = pieChart.segments[index]; | |
legendNode.style.backgroundColor = activeSegment.fillColor; | |
activeSegment.save(); | |
activeSegment.fillColor = activeSegment.highlightColor; | |
pieChart.showTooltip([activeSegment]); | |
activeSegment.restore(); | |
}); | |
helpers.addEvent(legendNode, 'mouseout', function(){ | |
var activeSegment = pieChart.segments[index]; | |
legendNode.style.backgroundColor = "transparent"; | |
}); | |
}); | |
helpers.addEvent(legendHolder.firstChild, 'mouseout', function(){ | |
pieChart.draw(); | |
});</script></body> | |
</html> |
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
img { | |
border: 1px dashed red; | |
margin-top: 20px; | |
} | |
br { | |
clear: both; | |
} | |
.pie-legend | |
{ | |
padding-left: 0; | |
list-style: none; | |
} | |
.pie-legend li | |
{ | |
display: block; | |
position: relative; | |
margin-bottom: 4px; | |
padding: 2px 8px 2px 18px; | |
cursor: default; | |
} | |
.pie-legend li span | |
{ | |
display: block; | |
position: absolute; | |
left: 0; | |
top: 0; | |
width: 12px; | |
height: 100%; | |
} | |
#legend { | |
float: right; | |
width: 100px; | |
} | |
#canvas-container { | |
float: left; | |
width: 350px; | |
} |
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
var data = [ | |
{ | |
value: 300, | |
color:"#F7464A", | |
highlight: "#FF5A5E", | |
label: "Red" | |
}, | |
{ | |
value: 50, | |
color: "#46BFBD", | |
highlight: "#5AD3D1", | |
label: "Green" | |
}, | |
{ | |
value: 100, | |
color: "#FDB45C", | |
highlight: "#FFC870", | |
label: "Yellow" | |
} | |
]; | |
var ctx = document.getElementById("canvas").getContext("2d"); | |
var pieChart = new Chart(ctx).Pie(data, { | |
animateRotate : false, | |
animateScale: false, | |
responsive: true, | |
tooltipCornerRadius: 0, | |
onAnimationComplete: function(){ | |
document.getElementById("url").src = pieChart.toBase64Image(); | |
} | |
}); | |
var helpers = Chart.helpers; | |
var canvas = document.getElementById("canvas"); | |
var legendHolder = document.getElementById("legend"); | |
legendHolder.innerHTML = pieChart.generateLegend(); | |
helpers.each(legendHolder.firstChild.childNodes, function(legendNode, index){ | |
helpers.addEvent(legendNode, 'mouseover', function(){ | |
var activeSegment = pieChart.segments[index]; | |
legendNode.style.backgroundColor = activeSegment.fillColor; | |
activeSegment.save(); | |
activeSegment.fillColor = activeSegment.highlightColor; | |
pieChart.showTooltip([activeSegment]); | |
activeSegment.restore(); | |
}); | |
helpers.addEvent(legendNode, 'mouseout', function(){ | |
var activeSegment = pieChart.segments[index]; | |
legendNode.style.backgroundColor = "transparent"; | |
}); | |
}); | |
helpers.addEvent(legendHolder.firstChild, 'mouseout', function(){ | |
pieChart.draw(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment