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

  • Home
  • SEARCH
  • 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 6777199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:07:10+00:00 2026-05-26T16:07:10+00:00

Hi I am trying to draw one line graph and for that I am

  • 0

Hi I am trying to draw one line graph and for that I am using this code.

DrawGraph dg = new DrawGraph(this);
    pane.addView(dg);
    dg.setData(10, 10, 100, 100);   //cords. for Firs Line
    pane.invalidate();
    dg.setData(100, 100, 100, 300);  //cords. for second Line
    pane.invalidate();

and this my DrawGraph class is here.

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

public class DrawGraph extends View{
Paint p;
int x1;
int y1;
int x2;
int y2;
Canvas fc;
int i = 0;

public DrawGraph(Context context) {
    super(context);
    p = new Paint();
    fc = new Canvas();
}

public void setData(int x1, int y1, int x2, int y2)
{
    this.x1 = x1;
    this.y1 = y1;
    this.x2 = x2;
    this.y2 = y2;
}

public void onDraw(Canvas c){
            c.drawLine(x1, y1, x2, y2, p);
   }
}

But the problem is there, I can see only one line in the graph (second line) and I need both Lines
I means all the Lines in graph at a time.
any solution please. Thanks.

  • 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-26T16:07:10+00:00Added an answer on May 26, 2026 at 4:07 pm

    You have called setData twice, so the second call will overwrite the first values you set.

    If you are trying to draw graphs, you can use a library such as AndroidPlot to do the heavy lifting for you. (http://androidplot.com/wiki/Home) There are other libraries but I’ve personally used AndroidPlot and it worked well for me – I had to draw 2 lines on a graph as well.

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

Sidebar

Related Questions

I am trying to draw a line my Code is this -(void) drawRect:(CGRect) rect
I am trying to draw a textured cube using just 8 vertices and one
I'm trying to draw a simple line graph which would use values from the
I made this application that lets the user draw a line on the screen
In the following code, I'm trying to draw two lines: One with a subpixel
I am trying to write a code to generate a graph like this: http://www.mathgoodies.com/lessons/graphs/images/line_example1.jpg
I'm trying to draw a line between one object and where the user touched.
This is probably an easy one for Android experts. I am trying to draw
I am trying to draw a line along with mouse move on a paper.
I am trying to draw in a web worker using html5 canvas. The worker

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.