Denny Lee

Ramblings of a data dork: from BI and Big Data to Travel and Food

Tech Tip Tuesday: HTML Donut Charts and Apache Web Server on Mac OSX

UntitledQuick tech tip for today, how to create HTML donut charts like the one below and use Apache Web Server on Mac OSX.  Hats off to the BI Happy Blog and Coolest Guy on the Planet Tech blog.   I wanted to quickly generate some mockup donut charts by using HTML – and being lazy, figured I would just borrow some code.

For starters, I needed to get Apache Web server started on my Mac OSX Mountain Lion – fortunately, the instructions are already provided – so here’s the link: Install and configure Apache, MySQL, PHP and phpMyAdmin on OSX 10.8 Mountain Lion.

The BI Happy Blog has a great one that allowed me to create a HTML donut chart with relative ease.   The original source code for this can be found at: http://bihappyblog.com/2012/03/29/google-visualization-donut-chart/

I have modified the code slightly so it can be run locally on my Mac OSX Mountain Lion web server – below is my version of it for your usage.

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
       var data = new google.visualization.DataTable();
       data.addColumn('string', 'Task');
       data.addColumn('number', 'Hours per Day');
       data.addRows([
       ['web',    roundNumber(11*Math.random(),2)],
       ['XML',      roundNumber(2*Math.random(),2)],
       ['json',  roundNumber(2*Math.random(),2)],
       ['avro', roundNumber(2*Math.random(),2)],
       ['protobuf',    roundNumber(7*Math.random(),2)]
       ]);
var options = {
width: 450, height: 300,
colors:['#ECD078','#D95B43','#C02942','#542437','#53777A'],
legend: {position: 'none'},
   pieHole: 0.5
//   animation:{
//       duration: 800,
//       easing: 'in'
//     }
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
function roundNumber(num, dec) {
 var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
 return result;
}
</script>
</head>
<body>
<div id="link_div" style="z-index: 3; position: absolute; left: 180px; top: 30px;">
<a href="javascript:drawChart()">Change Data</a>
</div>
<div id="chart_div" style="z-index: 1; position: absolute; left: 0px; top: 20px;"></div>
<div id="circle_div" style="z-index: 2; position: absolute; left: 180px; top: 127px;">
<!-- <img src="circle.png"></div> -->
<img src="http://bihappyblog.com/samples/circle.png"></div>
</body>
</html>


Enjoy!

About dennyglee

dork, scribe, geek, Microsoft data dork, ultimate frisbee fan, mountain climber (barely!),... occasionally awake

4 Comments on “Tech Tip Tuesday: HTML Donut Charts and Apache Web Server on Mac OSX

  1. Ron Keler
    September 5, 2012

    Thanks for the reference Denny. Best regards. – Ron

  2. Thank you so much Denny!!! great help.

  3. SutoCom
    September 6, 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Information

This entry was posted on September 4, 2012 by in Tech Tips Tuesday and tagged , , , .

Professional Microsoft SQL Server 2012 Analysis Services with MDX and DAX

Analysis Services Multidimensional and Tabular Reference all in one handy book!

@dennylee

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 2,002 other followers

Copyright

Copyright © 2012 Denny G Lee - All Rights Reserved
Follow

Get every new post delivered to your Inbox.

Join 2,002 other followers

%d bloggers like this: