-
-
Save ozelfatih/dd9bd2850f11959de0004d4db1fb5b42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Piechart = function(options){ | |
this.options = options; | |
this.canvas = options.canvas; | |
this.ctx = this.canvas.getContext("2d"); | |
this.colors = options.colors; | |
this.draw = function(){ | |
var total_value = 0; | |
var color_index = 0; | |
for (var categ in this.options.data){ | |
var val = this.options.data[categ]; | |
total_value += val; | |
} | |
var start_angle = 0; | |
for (categ in this.options.data){ | |
val = this.options.data[categ]; | |
var slice_angle = 2 * Math.PI * val / total_value; | |
drawPieSlice( | |
this.ctx, | |
this.canvas.width/2, | |
this.canvas.height/2, | |
Math.min(this.canvas.width/2,this.canvas.height/2), | |
start_angle, | |
start_angle+slice_angle, | |
this.colors[color_index%this.colors.length] | |
); | |
start_angle += slice_angle; | |
color_index++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment