Jump to content
  • Advertisement
Sign in to follow this  
technorabble

Basic Graphical Output, C#

This topic is 3238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been playing with c# and have a program which outputs number pairs to file, tab delimited. From there I've been visualising the output by copy-pasting the data into an Excel spreadsheet then making a scatter graph. Very pretty, but not very programmery. So I'm wondering whether there's anything built into c# which might allow me to get my program to plot those data points itself. I don't really have any idea where to start. Could someone point me in the right direction?

Share this post


Link to post
Share on other sites
Advertisement
Depends on what you want to do.

Do you want to create a bitmap (jpg, png, whatever) with a picture of a graph?

or do you want a GUI that plots the points?

I'll assume it's the latter for the moment (the most common choice). To do this, you use a GUI library. For C# your choices are either winforms or WPF. Googling either of those should get you started.

Share this post


Link to post
Share on other sites
Quote:
Original post by technorabble
Yep, it's the latter. My own digging around suggests GDI+ could be an option?


If your program is a Console app, you can just add a new item (Windows Form) into your project, add a PictureBox control, and from there all you would need to do is something like this... (I am passing the data generated to the form so it can draw it)


//Main Program
void blah()
{

MyDataTable Table = new MyDataTable();
Table.DoSomeFancyCalculations();
MyDisplayForm DisplayForm = new MyDisplayForm(Table);
DisplayForm.ShowDialog();
}



Then in your form's constructor...


using System.Drawing;
//Form Constructor
public MyDisplayForm(MyDataTable table)
{
InitializeComponent();
Bitmap buffer = new Bitmap(pictureBox.Width,pictureBox.Height);
Graphics g = Graphics.FromImage(buffer);

//you can now use the Graphics methods like g.DrawPolygon or g.DrawLines or whatever you need to render the data to the buffer
{
//Here's where you put the rendering code
}
//once rendering is done, we set the Image property of the pictureBox

pictureBox.Image = buffer;
}



the effect will be, your program calculates the data, initializes the form&it's controls, renders to a buffer, then sets the pictureBox image to be that buffer. the data will calculate, and a form with the data rendered will display that the user can then close.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!