Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:05:30+00:00 2026-05-27T15:05:30+00:00

I need a piechart for my App to display some data in different sections.

  • 0

I need a piechart for my App to display some data in different sections.
the piechart is ready and it also works fine but i need a clickable event when touched on a particular section in pie chart .Please let me know the code
Thanks in advance.
this is my android code

  public class PieActivity extends Activity 
{
/** Called when the activity is first created. */
float values[]={300,700,100,500};

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    LinearLayout linear=(LinearLayout) findViewById(R.id.linear);
    values=calculateData(values);
    linear.addView(new MyGraphview(this,values));

}
private float[] calculateData(float[] data)
{
    // TODO Auto-generated method stub
    float total=0;
    for(int i=0;i<data.length;i++)
    {
        total+=data[i];
    }
    for(int i=0;i<data.length;i++)
    {
    data[i]=360*(data[i]/total);            
    }
    return data;

}
public class MyGraphview extends View
{
    private Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
    private float[] value_degree;
    private int[] COLORS={Color.BLUE,Color.GREEN,Color.GRAY,Color.CYAN,Color.RED};
    RectF rectf = new RectF (10, 10, 200, 200);
    int temp=0;
    public MyGraphview(Context context, float[] values) {

        super(context);
        value_degree=new float[values.length];
     //   System.out.println("values"+value_degree);
        for(int i=0;i<values.length;i++)
        {
            value_degree[i]=values[i];
            System.out.println("degree"+value_degree[i]);
        }
    }
    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);

        for (int i = 0; i < value_degree.length; i++) {//values2.length; i++) {
            if (i == 0) {
                paint.setColor(COLORS[i]);
                canvas.drawArc(rectf, 0, value_degree[i], true, paint);
            } 
            else
            {
                    temp += (int) value_degree[i - 1];
                    paint.setColor(COLORS[i]);
                    canvas.drawArc(rectf, temp, value_degree[i], true, paint);
            }
        }
    }

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:05:31+00:00Added an answer on May 27, 2026 at 3:05 pm

    You could try this:

    • Override onTouchEvent in MyGraphView and check the action. Normally for ACTION_DOWN you should return true and on ACTION_UP handle the click.

    • When you handle the click, extract the relative event coordinates from the center of the chart, something like

      float relX = event.getX() - (rectf.right - rectf.left) * 0.5f;
      float relY = event.getY() - (rectf.bottom - rectf.top) * 0.5f;
      
    • Then you need to find the angle:

      float angleInRad = (float)Math.atan2(relY, relX);
      
    • Now you’ve got the angle but in radians and in the range -PI..PI. So:

      int degree = (int)((angleInRad + Math.PI) * 180 / Math.PI);
      
    • Now just find which interval (from value_degree) contains this value.

    Also note that since the coordinate system is upside down, you might need to use -relY instead of relY. Just try it and change it if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

need ask you about some help. I have web app running in Net 2.0.
Need some insight on how this works I have the following piece of code
I need to display a lot of charts on some kind of status page.
I'm building a Rails app that needs some data visualization. What is a good
Need some help about with Memcache. I have created a class and want to
Need to insert selected text on the page into textarea. There must be some
Need to call a filter function on some options based on a radio selected
I am trying to get a pie chart display correctly but have found there
I have a Flex project that I need to work on that using some
Need some advice to use iframe for widget or not. Will some addons/plugin block

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.