O'Reilly logo

HTML5 Canvas Cookbook by Eric Rowell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a pie chart

Pie charts are probably one of the most common data visualizations because they quickly give users a sense of the relative weights of data elements. In this recipe, we'll create a configurable Pie Chart class that takes in an array of data elements and produces a pie chart. Furthermore, we'll construct the Pie Chart drawing methods in such a way that the pie chart and label automatically fills up as much of the canvas as possible.

Creating a pie chart

How to do it...

Follow these steps to create a Pie Chart class that can automatically position and size a pie chart and a legend from an array of data:

  1. Define the constructor for the PieChart class which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required