Math Calculations
-
Hi all, This is hard to explain but I need some sort of Algorythm that will calculate a number for me. Basically, I am "trying" to build a class that will output a Graph for our web stats, within my code I have got the highest amount that will be shown on the graph, and now I need to set the Y Axis values. So at the moment, I have the values 0,2,0,90,172 because the highest value is 172 i'd like to some how generate a set of numbers like the following: 0,30,60,90,120,150,180 But since these values constantly change, I need some fancy way of calculating them. Anyone have any idea's? The reason why I ask, is because the Graph size will be 200hx700w (pixels) and regardless of the results I want them to fit without any further coding. Thanks Gav
-
Hi all, This is hard to explain but I need some sort of Algorythm that will calculate a number for me. Basically, I am "trying" to build a class that will output a Graph for our web stats, within my code I have got the highest amount that will be shown on the graph, and now I need to set the Y Axis values. So at the moment, I have the values 0,2,0,90,172 because the highest value is 172 i'd like to some how generate a set of numbers like the following: 0,30,60,90,120,150,180 But since these values constantly change, I need some fancy way of calculating them. Anyone have any idea's? The reason why I ask, is because the Graph size will be 200hx700w (pixels) and regardless of the results I want them to fit without any further coding. Thanks Gav
Gavin Roberts wrote:
because the highest value is 172 i'd like to some how generate a set of numbers like the following: 0,30,60,90,120,150,180
Round the highest number to be a multiple of 10, and then create a set with n steps with: number / n Example: highest value = 154 -> maxnumber = (int)(154 / 10) * 100 + 10 (But this will only work reliable in the range of 10-100 - I can write an algorithm for you that will work on any kind of numbers, up to a million and above, but I have no time right now. I might write it later for you if you need it :)) steps: n steps (e.g. 5) -> step = maxnumber / n then you can create your steps like this: 0, step, 2*step, 3*step, ... maxnumber regards
-
Hi all, This is hard to explain but I need some sort of Algorythm that will calculate a number for me. Basically, I am "trying" to build a class that will output a Graph for our web stats, within my code I have got the highest amount that will be shown on the graph, and now I need to set the Y Axis values. So at the moment, I have the values 0,2,0,90,172 because the highest value is 172 i'd like to some how generate a set of numbers like the following: 0,30,60,90,120,150,180 But since these values constantly change, I need some fancy way of calculating them. Anyone have any idea's? The reason why I ask, is because the Graph size will be 200hx700w (pixels) and regardless of the results I want them to fit without any further coding. Thanks Gav
if I understood the question correctly: take the highest number (in our example its 172) and do the following: 172 / 10 = 17.2 -- but if it is "int" we will get --> 17 17 + 1 = 18 // add 1 18 * 10 = 180 // multiple by 10 and you rounded up the heighest number. so the algorithm is: roundUP(int x) { int result; result = x/10; result++; result*=10; if(result > 200) result = 200; return result; } it seems to me a pretty efficint way to calculate, unless I didn't understand the question. hope it helps!
-
Hi all, This is hard to explain but I need some sort of Algorythm that will calculate a number for me. Basically, I am "trying" to build a class that will output a Graph for our web stats, within my code I have got the highest amount that will be shown on the graph, and now I need to set the Y Axis values. So at the moment, I have the values 0,2,0,90,172 because the highest value is 172 i'd like to some how generate a set of numbers like the following: 0,30,60,90,120,150,180 But since these values constantly change, I need some fancy way of calculating them. Anyone have any idea's? The reason why I ask, is because the Graph size will be 200hx700w (pixels) and regardless of the results I want them to fit without any further coding. Thanks Gav
There is an article here on Codeproject presenting A flexible charting library for .NET[^] that implements the described behaviour. Either use this library or take a look at the source code to see how the autoscaling is accomplished.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Hi all, This is hard to explain but I need some sort of Algorythm that will calculate a number for me. Basically, I am "trying" to build a class that will output a Graph for our web stats, within my code I have got the highest amount that will be shown on the graph, and now I need to set the Y Axis values. So at the moment, I have the values 0,2,0,90,172 because the highest value is 172 i'd like to some how generate a set of numbers like the following: 0,30,60,90,120,150,180 But since these values constantly change, I need some fancy way of calculating them. Anyone have any idea's? The reason why I ask, is because the Graph size will be 200hx700w (pixels) and regardless of the results I want them to fit without any further coding. Thanks Gav
hi try to visit this links: http://www.carlosag.net/Tools/WebChart[^] http://www.carlosag.net/Tools/WebChart/samples.aspx[^] Tamimi - Code
Tamimi - Code