• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

drawing lines

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the thing:
say you have 400 records and want to draw a graph line out of them, and you have 400 pixels wide area. That would come out as each record takes 1 pixel.
Q: How to draw a graph line that have 401 or 203 or 891 or some other number of records in 400 pixel area (while the smallest line you can draw with "g.drawLine" is 1 pixel)?
I really need this one!!
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would imagine that you could figure out the proportion of the new size as a double value - ie.
double prop = (double)amountOfEntries / (double)widthOfGraph;
Then you multiply the entry locations by this proportion to get the right location (or close enough). ie.
int pixelValue = (int)(prop * (double)location);
Hope that helps.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yours is an interesting situation.
There are couple of approaches based on the options you have.
Do you have represent every single record on the graph?
If not,
Let us say you have alloted 800 as the max you could get.
and you actually get only 600. One way of dealing with this is
split it into multiples that would also be multiples of the
max. So represent the first 400 as it is and for the next 200,
use a broader graph scale so you would drawing a line every alternate pixel.
If the actual exceeds, the max, you can represent every alternate intially with a narrow scale and then switch to regular scale and represent the most recent.
Here the assumption is that most recent is more important.
Well, my solution is a result of 2 mins of thinking so this is more of a quick response.
I hope this gives you some off the track info.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic