soandos
soandos

Reputation: 5146

Building a scatterplot class

Here is the way that I think a scatter plot should be built in C# (at a decently high level of abstraction).

  1. Create a blank image
  2. Use TextRenderer to draw the axis labels and scales (horizontal will not be so trivial, but will still be manageable).
  3. Draw some lines that will be the ticks on the axes and the lines for the axes themselves
  4. Draw some circles (not 100% of how to do that, but it can't be too hard) based on the points listed in some data-set.
  5. Display the image in a pictureBox.
  6. Create a function that will be called on MouseHover that will display some details about that point in a tool-tip.

Does this even make sense? Am I using the wrong controls for the job? Is there some code in .NET that will do a large part of this already (the chart class seems good only for bar graphs)? Is there a way to access excel's plotting capabilities from C#?

To me, all of this seems quite contrived, and I would appreciate input on how to better design a scatter-plot class.

Upvotes: 0

Views: 5079

Answers (2)

Mike Zboray
Mike Zboray

Reputation: 40838

The Microsoft Chart Controls library can do much more than bar graphs. It is included in the .NET 4 framework, but is also available as a separate download for .NET 3.5 SP1. The samples are available here and demonstrate most of the major features.

Upvotes: 2

Superbest
Superbest

Reputation: 26612

No, that does make sense. I don't really know how "professionals" do it, but when you need a quick scatter plot that's pretty much how you would make one. Some things to keep in mind:

  • You want the Draw() method to sit on top and take transformed coordinates of the data points. This is because you will eventually want zooming and panning. Taking a page from 3D graphics programming and just using an explicit transformation matrix (there's a few in XNA) would probably save you a lot of trouble.
  • You might want to have a general "draw point" function which calls specialized sub-routines to draw individual points, so you can easily switch between different kinds of points (cross, circle, dot, square, diamond, and so on). Also color.
  • How do you intend to handle very large numbers of data points? That can quickly grind a poorly thought out Chart API to a halt in my experience.

Upvotes: 1

Related Questions