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 6721013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:16:47+00:00 2026-05-26T09:16:47+00:00

I am working on a graphing class (in javascript) which uses canvas. This is

  • 0

I am working on a graphing class (in javascript) which uses canvas. This is just for experimental / learning purposes. Currently the graph scales correctly based on whatever height and width the canvas is set at. This is not a problem, and here is basically what I am doing to plot the correct coordinates [pseudo-code].

point[0] = [10, 15]
point[1] = [20, 10]
point[2] = [30, 20]
point[3] = [40, 15]

canvas width = 300
max x = 40

so for any given point:

position x = ( point[i][0] / max x ) * canvas width 

simple enough. I get a ratio, then multiply it by the canvas width to plot it at the correct pixel.

The problem however, is coming up with an equation that would cause the minimum value of x to reside at 0 on the x coordinate of the graph, and the max value to be at the maximum point of the graph (which it already does because of the 1:1 ratio in my current equation). Currently the minimum value of x (10 in the example), resides at 75px in the x coordinate, because of the 1:4 ratio being multiplied to the canvas’ width.

tldr / summary: I need to make a graph in which the minimum value is plotted at the beginning of the graph(0,0), and the maximum value plotted to the end.

  • 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-26T09:16:48+00:00Added an answer on May 26, 2026 at 9:16 am

    try calculating a value for pixel-width-per-point first.

    e.g.

    widthPerPoint =  canvasWidth / (maxX - minX)
    

    then your position can be normalised to zero by subtracting the minimum value:

    position = widthPerPoint * (point[i][0] - minX)
    

    for your first example

    widthPerPoint = 300 / (40 - 10) = 10
    
    position = 10 * (point[i][0] - 10) = 10 * 0 = 0
    

    and for the others:

      point[0] = [10, 15] -> 0
      point[1] = [20, 10] -> 100
      point[2] = [30, 20] -> 200
      point[3] = [40, 15] -> 300
    

    at least I think that’ll work….

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

Sidebar

Related Questions

Working with python interactively, it's sometimes necessary to display a result which is some
I am trying to get a sample program working with JUNG , a graphing
I'm working on a large website project that makes heavy use of in-page graphing
Working on this page: http://www.karlsenner.dreamhosters.com/about.php and having trouble with the navigation in IE6. It
I have been working on projects that deal with 2-Dimensional graphing, UML diagramming and
I'm working on a graphing applications that basically graphs equations with on an HTML5
Has anyone already used Flot in Android? I've been reading this http://rapidandroid.org/wiki/Graphing and i've
Working with C#. I have an abstract class that I use to read/write settings
Working of foreach: As I know, foreach is a loop which iterates through a
In Python, I have a Graph class that has a dictionary of vertex objects.

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.