Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryGenerators and Converters

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Pie Chart Generator

Have you ever wanted pie charts for your web pages? And easy to implement, too?

Here you go!

Use the Pie Chart Code Generator further below. Specify the name and number value for each pie slice and then click the button.

The generated code is copy and paste, ready for your web page. It's HTML and JavaScript. No PHP required.

The code uses Google's chart API.

The pie chart will have the API's default colors and fonts. The Google developers site for charts provides information for changing the defaults.

Width-responsive Pie Charts, But Not Dynamic

The pie charts are initial-width responsive, not dynamic-width responsive.

In other words, the pie chart fits into any mobile device or desktop browser window when the page is loaded.

But the pie chart won't dynamically change its size if you adjust the browser width after the page has loaded. You'll need to reload the page after adjusting the browser width.

It has to do with how Google's chart API delivers the pie charts.

Not a Static Example Pie Chart

The pie chart a bit further below is changeable by you, not a static example.

When the page first loads, the pie chart shows the relationship between the number of pages in 3 areas of the Willmaster.com website. The numbers include this article but won't be updated as more are published or others removed.

Instead of example pie chart, let's call it the pie chart of the article.

Use the pie chart generator further below to change it. Create your own pie charts.


LOADING...

This code renders the pie chart you see above. It can be pasted into any web page where the pie chart is to be published.

<!-- Code generator provided by Will Bontrager Software LLC at https://www.willmaster.com/library/generators/pie-chart-generator.php -->
<!-- The div where the pie chart will be placed. -->

<div id="chart_div" style="width:100%; max-width:500px; height:400px; margin:0 auto;"><hr>LOADING...<hr></div>

<!-- This first JavaScript adjusts the height of the pie chart div according to the actual width of the pie chart div -->
<script type="text/javascript">
var d = document.getElementById("chart_div");
d.style.height = parseInt((d.scrollWidth/5*4)+1) + "px";
</script>

<!-- The following JavaScript is for Google's charts API. -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load( 'visualization', '1.0', { 'packages':['corechart'] } );
google.setOnLoadCallback(drawChart);
function drawChart()
{
   var data = new google.visualization.DataTable();
   data.addColumn( 'string', 'Area' );
   data.addColumn( 'number', 'Pages' );
   data.addRows([
         ['Article Library', 511],
         ['Blog', 275],
         ['Commercial Software', 152],
      ]);
   var options = { 'title':'3 Willmaster.com Area Page Counts', 'legend':'bottom', 'is3D':true, };
   var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
   chart.draw(data, options);
} // function drawChart()
</script>

The Pie Chart Code Generator

The form is pre-filled with the data used for rendering the pie chart of the article using the above code.

After submitting the form, this page will reload. The pie chart for the code you generated will be the pie chart of the article.

It the result isn't what you intended, you can update the form and submit it again.

Pie Chart Code Generator

All fields except Pie chart data are optional.

Pie chart title.

Position of labels in relation to pie chart.
Top Right Bottom Left

3D pie chart? Yes No

Pie chart data (required).

Specify the label and the number separated with a vertical bar ("|") character, one line per set.

Maximum pixel width of div containing pie chart.

Pie chart horizontal alignment.
Left Right Centered

Use the Pie Chart Code Generator, then copy the generated code to paste the pie chart into your web pages.

It's outside the scope of this article, but if you're JavaScript proficient you'll see the code that can be modified to add, delete, and change the pie slices. With a bit of PHP, it's possible to automatically draw pie charts using data obtained from a database.

As it is, with no advanced knowledge required, you can use the generator to create pie charts and paste them into your web pages. Easy.

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC