Results 1 to 3 of 3

Thread: VB6 - Melas: Line Charting Classes

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,834

    Red face VB6 - Melas: Line Charting Classes

    Why Melas?

    I needed an alternative to the MSChart control for creating simple line charts in batch mode. MSChart can do the job just fine with some fiddling, however I needed to create these charts and write them as JPEG or PNG files for direct serving from a Web server. The only snag is that to capture the drawn chart from the MSChart control you need to use the clipboard and I didn't want to disturb its contents since a user might well be working while a background charting operation was going on.


    What is Melas?

    There is a main class called Melas and a set of "child" classes it uses to represent various things (axes, plots, legends, etc.). You create an instance of Melas and initialize it with a reference to some VB6 object having an hDc so that it can be drawn on. In most cases this will be a Form, a PictureBox, or a UserControl.

    From there you use some MSChart-like operations to flesh out the rest and plot your lines.


    Still Rough

    There is more to do here yet, especially in terms of dealing with pesky boundary conditions (do I subtract a pixel here or not?), making sure rotated text gets positioned correctly, etc.

    However I decided to post it as-is.

    For one thing it is still simple enough that somebody could use it as an example or jumping-off point for creating their own more comprehensive MSChart alternative. For another I am taking the code in a specific direction for my own purposes that will make the logic more complex to follow as well as being less general-purpose in nature.


    Notes

    There is no code here to grab the resulting chart image and save it, the focus here is drawing the chart. You can use simple .SavePicture() operations to create BMP files or else use another technique to grab and save in other formats.

    The core of the Melas classes is the Canvas class, which is primarily meant to create non-clipped and clipped regions where the Y-coordinate is flipped (0 at the bottom instead of the top as in regular VB6 drawing) and both X and Y are scaled without using a custom ScaleMode.

    Inside the Melas class you will find places where it uses Canvas coordinates, and others where it draws directly and uses VB6 cordinates. Sorry about the confusion - this is just a heads-up to anybody trying to unravel the logic.

    The attachment contains the Melas classes and 5 demos. There are some images in there and a small database, which is why the attachment is so large. Melas itself is fairly small and doesn't add a ton to the size of compiled programs.
    Attached Images Attached Images    
    Attached Files Attached Files

  2. #2
    New Member
    Join Date
    May 2021
    Posts
    12

    Re: VB6 - Melas: Line Charting Classes

    Hi,dilettante, you provided a very nice class group for simply graphing. Here I have two question for you to help me. 1) I Test the tick grid drawing in my program , it shows the width/height step is not exactually the same size; 2) If I add 3 or 4 Y coordinates ,is't hard to draw complete grids. Thanks.

  3. #3
    New Member
    Join Date
    May 2021
    Posts
    12

    Re: VB6 - Melas: Line Charting Classes


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
  •  



Click Here to Expand Forum to Full Width