Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matijagrcic/7c0f1c994bdcd0df41cd to your computer and use it in GitHub Desktop.
Save matijagrcic/7c0f1c994bdcd0df41cd to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<style>
#piechart {
top: 0;
left: 0;
width:100%;
height:100%;
}
.google-visualization-tooltip{
display:table;
}
g{
cursor:pointer;
}
</style>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(initChart);
$(window).on("resize", function (event) {
initChart();
});
function initChart() {
var options = {
legend:'none',
width: '100%',
height: '100%',
pieSliceText: 'label',
tooltip: { isHtml: true },
chartArea: {
left: "3%",
top: "3%",
height: "94%",
width: "94%"
}
};
var data = google.visualization.arrayToDataTable([
['Risk Factors', 'Percentage'],
['Smoking', 20],
['Alcohol', 20],
['Medicines', 20],
['Diet', 20],
['Lifestyle', 20]
]);
drawChart(data, options)
}
function drawChart(data, options) {
var tooltip = [
"Cigarattes and other forms on smokeless tobacco promote osteoporosis",
"Excessive alcohol consumption accelerates bone loss",
"Chronic steroid use and other medications can promote osteoporosis",
"Diet deficient in osteoporosis puts you at risk of osteoporosis",
"Lifestyle without exercise increases bone loss and makes muscle weak"
];
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
var sliceid = 0;
function eventHandler(e){
chart.setSelection([e]);
try {
selection = chart.getSelection();
sliceid = selection[0].row;
}
catch(err) {
;
}
$(".google-visualization-tooltip-item-list li:eq(0)").css("font-weight", "bold");
$(".google-visualization-tooltip-item-list li:eq(1)").html(tooltip[sliceid]).css("font-family", "Arial");
}
google.visualization.events.addListener(chart, 'onmouseover', eventHandler);
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="piechart"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment