Reading numbers from a file and using in a chart?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Reading numbers from a file and using in a chart?

  1. #1
    Join Date
    Feb 2011
    Posts
    5

    Question Reading numbers from a file and using in a chart?

    Hi All,
    I'm a first time poster on this forum but have used it a few times now for looking up information and thought I would sign up so I could learn more about C# and other C platforms as I'm a brand new coder, learning myself from the internet and will probably need a hand with coding in the future!

    The problem I have at the moment is probably a really simple solution but I simply lack the know how of how to do so but I am using tutorials on the internet to create small console applications before I start with the windows forms etc.

    An example of the application I am building is an app that takes a set of numbers from a text file and then I want to put said numbers in a graph by sorting them and exporting in a chart.

    I have imported the number using the StreamReader class which I assume is correct, but now I am stuck because I don't understand how these numbers are stored and then used in a graph? All i've been able to do is make the numbers display as a list in the console window!

    I am sure this is a really newbie question and is one of the most simple questions ever but I'm having problems so if anyone could possibly help?

    I can't find anything on the internet about it, which leads me to believe even further that it is a newbie question; perhaps I am wording it incorrectly!

    Thanks in advance!

  2. #2
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Reading numbers from a file and using in a chart?

    Eh, I'm not sure how easy graphing is in Windows Forms. I know there is a WPF toolkit out there that provides functionality for creating a multitude of different graphs but there's a bit of a learning curve with WPF.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  3. #3
    Join Date
    Feb 2011
    Posts
    5

    Re: Reading numbers from a file and using in a chart?

    yeah im still trying at the moment! but im actually writing it in a console application, not a windows form if that helps.

    thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Reading numbers from a file and using in a chart?

    Start by downloading the samples from here
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Reading numbers from a file and using in a chart?

    Oh, well that's interesting, haha. I haven't seen anyone do that in a long time. Really, you could use many of the methods exposed statically by the Console class, such as the Console.SetCursorPosition() and Console.Write() methods. But it would probably be a pain in the rear to make a graph with the console, that's old school. There should also be a way to change the color of the console where the cursor is currently located if you wanted different colored lines. I know we messed around with it in C++ awhile back, but in C# you might have to make some external function calls to the WinAPI to get it to work.

    While it's certainly not easy, it's entirely possible. Give me a sec and I'll show you how to make a simple graph with one line of data.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  6. #6
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Reading numbers from a file and using in a chart?

    Quote Originally Posted by dglienna View Post
    Start by downloading the samples from here
    No way, this is too old school to pass up
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  7. #7
    Join Date
    Feb 2011
    Posts
    5

    Re: Reading numbers from a file and using in a chart?

    well i thought by using the c# console application as a start it would ease me into it a bit better than creating windows forms straight off the bat!

    ill check out the samples thanks!

    the graph isnt that important at the moment, first im just trying to read the numbers in...i can only get them to be displayed in the console..but i dont understand how to use them in the application!

  8. #8
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Reading numbers from a file and using in a chart?

    Ok, that's more difficult than I though The console becomes kind of hostile when your data can have varying ranges. Maybe you better check out the link dglienna posted instead, hahaha.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  9. #9
    Join Date
    Feb 2011
    Posts
    5

    Re: Reading numbers from a file and using in a chart?

    i know im still struggling haha!
    do you think it would be easier to import the list of numbers using stream reader, sort them and then export the bar chart as a text file or a web page etc?
    im still having problems regarding using the numbers read from the text file.. i dont know how i convert them/use them in the application :?

  10. #10
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Reading numbers from a file and using in a chart?

    Quote Originally Posted by beadscreen View Post
    i know im still struggling haha!
    do you think it would be easier to import the list of numbers using stream reader, sort them and then export the bar chart as a text file or a web page etc?
    im still having problems regarding using the numbers read from the text file.. i dont know how i convert them/use them in the application :?
    Well, there's always Crystal reports. What are you trying to convert the numbers to? How are you reading them into the program?
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  11. #11
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Reading numbers from a file and using in a chart?

    Quote Originally Posted by beadscreen View Post
    well i thought by using the c# console application as a start it would ease me into it a bit better than creating windows forms straight off the bat!
    This project will not help you ease into anything. Creating graphs in a console window is a pain in the a@@ (as you already know) and you're not learning anything very valuable by doing it.

  12. #12
    Join Date
    Feb 2011
    Posts
    5

    Re: Reading numbers from a file and using in a chart?

    I am reading them in using stream reader but at the moment i think all i have managed to do is display the numbers in the text file, they are no use! I am trying to read them into the program and then using a sum, convert them into a percentage for a bar chart...think ive got ahead of myself a bit!

  13. #13
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Reading numbers from a file and using in a chart?

    Quote Originally Posted by beadscreen View Post
    I am reading them in using stream reader but at the moment i think all i have managed to do is display the numbers in the text file, they are no use! I am trying to read them into the program and then using a sum, convert them into a percentage for a bar chart...think ive got ahead of myself a bit!
    Methinks you would be better served by creating a Windows Forms application, my friend. Windows Forms applications are much friendlier when it comes to manually position controls and the like. Plus, I'm sure there's a free toolkit out there for creating graphs with Windows Forms. After a few years of banging your head trying to reinvent the wheel, you begin to look for wheels that are already built with high performance tires and spinning hubcaps that you can just bolt on and use!
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center