Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Math Calculations

Math Calculations

Scheduled Pinned Locked Moved C#
data-structuresquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gavin Roberts
    wrote on last edited by
    #1

    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

    L G S T 4 Replies Last reply
    0
    • G Gavin Roberts

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • G Gavin Roberts

        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

        G Offline
        G Offline
        Green Fuze
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • G Gavin Roberts

          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

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          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

          www.troschuetz.de

          1 Reply Last reply
          0
          • G Gavin Roberts

            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

            T Offline
            T Offline
            Tamimi Code
            wrote on last edited by
            #5

            hi try to visit this links: http://www.carlosag.net/Tools/WebChart[^] http://www.carlosag.net/Tools/WebChart/samples.aspx[^] Tamimi - Code

            Tamimi - Code

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups