You are here:

Java/divide circle into parts and fill with diff color


Respected Sir/Mam,

I hv to create reports in java via coding and i have to of draw graphical reports (circle) like this approx as shown in following image:

Can you please give me some idea hw to create a circle (like that) and divide it into different parts and fill thoes parts with different color.


You can use the fillArc method in Graphics to do this. Your code would look something like:

Color[] colors = ...; //Fill in for the colors you want to use
double[] percentages = ...; //Fill in with the percentage of the circle.
double startPercentage = 0.0d;
for(int i = 0; i < percentage.length; i++) {
  g.fillArc(x,y, width, height, startPercentage * (Math.PI * 2), percentages[i] * (Math.PI * 2)); //change x,y,width,height to the rectangle area you want to put the pie chart.
  startPercentage += percentages[i];


All Answers

Answers by Expert:

Ask Experts


Artemus Harper


I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.


I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Washington State University

MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2017 All rights reserved.