Posted By
|
Message
|
lembi2001
Registered 01/04/2005
Points 608
|
10th September, 2014 at 10/09/2014 20:18:49 -
I've managed to create a graphing system for an app I'm creating but I'm having a couple of issues. The biggest one I have is the "tick marks". The graph system is completely dynamic and can plot a bar for every item in a list however I have got lines across the graph area at every tenth of the axis height. I want to put the number counts on each line so what I need to do is round up the highest number that is plotted to the nearest 50 (this stops .5 numbers etc...) so that I can then divide the number by 10 and display it on each line.
e.g.
Item 1 = 20
Item 2 = 25
Item 3 = 57
Item 4 = 86
Item 5 = 10
Obviously the nearest 50 here is 100, My graph would then display 100 as the highest tick mark and 90 down to 10 and then 0 at the origin.
The other issue I have is labelling the bars on x axis. I wanted to the text to be at about a 45 degree angle however as the labels are also dynamic this is proving to be quite difficult as I cannot rotate text strings. I looked at a blitting example using actives however it seems like it would be quite difficult to adapt this to my requirements.
Edited by lembi2001
n/a
|
Pan-tosser
Registered 24/10/2008
Points 520
|
11th September, 2014 at 11/09/2014 04:18:38 -
That's a good one. I'm not sure what your issues are or how far you have gotten. But i don't think it should be to hard to identify the largest number by using a loop and looping threw that loop the number of items you have.
Then once you found the highest item. I'd try running another loop that times the loop index by 50 and once that value is large than the highest that is the number you round too.
For the graphics i'm sure their has to be a good extension for text that will work.
Seems like a lot of work for a bar graph. I've made them before using graphics counters. I understand though sometimes you just got to go custom.
https://www.facebook.com/nathon.brown.7
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
11th September, 2014 at 11/09/2014 15:59:29 -
Like Pan-tosser says, you'll want to use a loop to find the highest value.
Rounding up to the next multiple of 50 is then pretty straightforward - you can just say: Ceil( highest_value / 50.0) * 50
The obvious thing for a chart would be to just draw *everything* on to a Surface object, which also allows you to write text at an angle.
n/a
|
lembi2001
Registered 01/04/2005
Points 608
|
11th September, 2014 at 11/09/2014 19:45:16 -
For some reason the Ceil(Value /50)*50 was giving me the closest 50 when rounding down. However adding 50 like this resolved it:
(ceil(value/ 50)*50)+50
I have used pan-tosser's suggestion of using counters and will look at the surface object for the text.
Cheers
n/a
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
12th September, 2014 at 12/09/2014 14:20:53 -
That's because you said "value / 50" not "value / 50.0", so MMF2 rounded off the result of the division, making the "ceil()" part pointless.
Like I said, I'd just use a surface object for everything - it's easy to draw bars as just colored rectangles, etc. No point messing around with counters, actives, etc.
n/a
|
lembi2001
Registered 01/04/2005
Points 608
|
12th September, 2014 at 12/09/2014 15:41:36 -
My bad, just noticed that
I couldn't be bothered working out how to draw the shapes on the surface object lol. It's done now so I'm happy.
Thanks
n/a
|
Pan-tosser
Registered 24/10/2008
Points 520
|
12th September, 2014 at 12/09/2014 15:58:39 -
I've never used the ceil() function before. Does it just round off numbers.
https://www.facebook.com/nathon.brown.7
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
13th September, 2014 at 13/09/2014 17:39:05 -
ceil() always rounds up
floor() always rounds down
round() always rounds to the nearest integer
int() basically just removes everything after the decimal point - meaning it always rounds towards zero (positive numbers get rounded down; negative numbers get rounded up)
n/a
|
Pan-tosser
Registered 24/10/2008
Points 520
|
13th September, 2014 at 13/09/2014 20:40:43 -
I didn't know media fusion had those abilities, sweet.
https://www.facebook.com/nathon.brown.7
|
|
|