Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pie chart in Java script

Status
Not open for further replies.

selani

Programmer
Apr 30, 2003
35
IN
can anyone tell me how to generate a pie chart on the fly in client side using javascript?

or where will i likely find materials on this....

thanx in advance.
 
It's easy.

First, you write a function that builds a pie chart on the fly onto a "2D array" (not technically possible in JavaScript, but there's a workaround in the examples at faq216-3516). Then you call a graphics plotting routine using that array (not technically possible in JavaScript, but there's a workaround in the examples at faq216-3516).

Your pie chart function will probably have a call like this:

Code:
PieChart(element1, element2, element3, etc.);

where each element is an array:
[value][RGBColor][label]

The function adds all the incoming values together and then uses the total and sub-values to produce angles of the appropriate value, plotting them onto the 2D array graph.

One of the examples in faq216-3516 is building a circle mathematically, so some of the calculations are already laid out for you there.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top