Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data
Generating Diagrams From Data Generating Diagrams From Data
Generating Diagrams From Data
Go Back  Xtreme Visual Basic Talk > > > Generating Diagrams From Data


Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2008, 12:51 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default Generating Diagrams From Data


Hello,
I wonder how programmers usually read data, and then generate diagrams; such as this one.
A better example may be the relationships representation in MS Access. Different elements can be moved and the diagram will react accordingly.

I'm not sure wehther or not this has something to do with dynamicly-created form controls. But last week I gave it a try and managed to read a txt file and then create a Label dynamicly for each line in the file. I also managed to layout the labels so that a label didn't cross the left edge of the form. If a label reached there, the flow wraped.

But what if we go beyond that, and consider a txt file in which each line contains information about an entry and its parent entry (if any). Such as this txt file:
IdOfEntry-Entry-IdOfParentEntry
Code:
1-Family
2-Sciences
3-Father-1
4-Mother-1
5-Brother-1
6-Sister-1
7-Cars
8-Biology-2
9-Ford-7
10-Mathematics-2
etc...

It's clear that the data here is best represented using the TreeView class, like this. But what if I want to generate a diagram from it so that I have more control over the way I display data, and for better understanding.

Is it done by:
  • adding controls to a form and always adjusting their Top, Left values,
  • drawing lines between certain points (need to know X, Y values!) to represent connection for example,
Is this the correct way of how charts and diagrams are normally created?
in other words, what are the essentials of creating digrams/charts from data?

YOURS,
Reply With Quote
  #2  
Old 06-25-2008, 01:17 PM
darkforcesjedi's Avatar
darkforcesjediGenerating Diagrams From Data darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

Quote:
what are the essentials of creating digrams/charts from data?
It's not as hard as it may seem at first. I assume your goal is to represent a hierachy or tree and only data of this type.

This is easily accomplished with either user controls or classes. One of the great things about controls and classes is they have the ability to contain other controls and classes.

If you're just trying to recreate the first picture you can create a class that represents a single node. It could have properties like the node's text and the color you use to draw it. But... the class can also contain a collection of children, which are of the same class. This allows you to store the items in a hierarchical way.

Once that's done you can do something like:

Code:
Sub MakeTree(TopLevel As MyClass)
    For Each m As MyClass In TopLevel.Children
        'Call a subroutine to draw m.
        'Since TopLevel is its parent, you
        'can choose where to draw m
        'based on its parent and the last
        'drawn sibling

        'Now draw any children of this node
        MakeTree(m)
    Next
End Sub

If you need more of an explanation I'm sure I or others here can help.
__________________
To err is human; to debug, divine.
Reply With Quote
  #3  
Old 06-25-2008, 01:38 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

darkforcesjedi thank you for the fast reply.
Quote:
This is easily accomplished with either user controls or classes. One of the great things about controls and classes is they have the ability to contain other controls and classes.
Very nice. I will try writing a class.
Thank you again.
Reply With Quote
  #4  
Old 06-25-2008, 07:15 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

I'm trying to write the class but my Object Oriented programming is bad.
When I say (just for example):
Code:
For Each dataTable1 As DataTable In myDataSet.Tables
What is the type of "Tables" here? Is it a Collection, List, Array, or what?
How can a DataSet have more than one DataTable and they can be indexed?
I already know that a class may have an array of another class as a "member variable", which is qualified using an instance of the class.
Code:
Public Class CarCustomer
    Private favouriteColors(3) As Color
End Class
Now I can Say:
Code:
Dim customer1 As New CarCustomer()
customer1.favouriteColors(0) = Color.Red
But I'm really confused about "Tables" and also "Nodes", "Controls", and a lot of things there which seem like arrays in VB.Net.

YOURS,
Reply With Quote
  #5  
Old 06-25-2008, 07:41 PM
darkforcesjedi's Avatar
darkforcesjediGenerating Diagrams From Data darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

I'll make a little example and post it.
__________________
To err is human; to debug, divine.
Reply With Quote
  #6  
Old 06-25-2008, 08:39 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Many thanks, darkforcesjedi.
Reply With Quote
  #7  
Old 06-25-2008, 08:55 PM
darkforcesjedi's Avatar
darkforcesjediGenerating Diagrams From Data darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

Here you go. It's commented. Step through it in the debugger to follow along. You can add any properties or variables you want to any of the classes. I just made a barebones tree with a barebones collection of nodes. Each node only has a "Text" but that's easily expandable.

It can be hard to wrap your mind around at first so feel free to post more questions.
Attached Files
File Type: zip Tree.zip (11.9 KB, 10 views)
__________________
To err is human; to debug, divine.
Reply With Quote
  #8  
Old 06-25-2008, 09:30 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

I'm speechless. Now I am going to study it carefully because I have been looking for an example like this one for a long time.
Many thanks, arkforcesjedi.

YOURS,
Reply With Quote
  #9  
Old 06-29-2008, 07:28 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Hello darkforcesjedi, thank you very much for helping me with the very good example. I've benefited alot from it. Thank you.

In the last few days, I read your exmaple and I hope that I understood it.
In fact it was so difficult that I first had no choice but to memorize it! The most ambiguous parts were/are:
  • the differentiation between the Node class and the NodeCollection class. I thought that we only needed the Tree and Node classes, if it were possible that a node could have children nodes; that is: member variables of type Node (same class).
  • the differentiation between a property and a public member variable (e.g. Count and _Count, Children and _Children), why not using one of each only?
  • also understanding the way it works is very difficult even if I use the debugger to keep track of execution. Recursive methods are neat but exhausting.

Given your guidelines, I wrote a program which is almost identical to the one you gave me, except that the Node class inherits from the Label class, and the nodes are read out from a txt file.

Complete VS 2005 project here. Screenshot here.

I appreciate you help which was so useful.
YOURS,

Last edited by Adel99; 06-29-2008 at 07:51 AM.
Reply With Quote
  #10  
Old 06-29-2008, 11:31 AM
AtmaWeapon's Avatar
AtmaWeaponGenerating Diagrams From Data AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I have some comments on your comments; if that makes any sense.
  • The reason for the NodeCollection was likely to mimic how the TreeView works. The TreeView.Nodes property is a type like this, and the TreeNode.ChildNodes property is as well.

    However, there's no need to actually implement the class as darkforcesjedi did. You can make a strongly-typed collection class by just inheriting from a generic collection class:
    Code:
    Public Class TreeNodeCollection
        Inherits Collection(Of Node)
    End Class
    The method darkforcesjedi chose is similar to the .NET 1.1 practice of manually creating a strongly-typed collection, since there were no generics.
  • This was probably an error based on the principle, "This is an example, pay attention to the method, not the implementation." Member variables should always be private. If you want them to be public, make a property that exposes it.
  • Try writing iterative methods to traverse a tree. The most natural and easiest way to work with a tree is recursion: you write one method that knows how to handle the node's value, and have it call itself on any child nodes. An iterative solution would be quite difficult to write.
That's a cool extension of his example you made, though, it looks like you understand the concepts.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #11  
Old 06-29-2008, 05:36 PM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Really thanks to both of you.

My class is like the following:
Code:
Public Class NodeCollection
    Private _Nodes As New ArrayList
    '...
    'other member variables and methods go here
    '...
    Default Public Property Item(ByVal index As Integer) As Node
        Get
            Return _Nodes(index)
        End Get
        Set(ByVal value As Node)
            _Nodes(index) = value
        End Set
    End Property
End Class
I wanted to use the For Each ... In statement, so I said:
Code:
        For Each n As Node In MyTree.Nodes
            MsgBox(n.Text)
        Next
It gave me this error: "Expression is of type 'Tree.NodeCollection', which is not a collection type".
So I though it wanted the ArrayList variable which is: _Nodes. Keeping it Private as AtmaWeapon suggests, I created a new property besides the Item property:
Code:
    Public Property Nodes()
        Get
            Return _Nodes
        End Get
        Set(ByVal value)
            _Nodes = value
        End Set
    End Property
It worked but it had this form:
Code:
        For Each n As Node In MyTree.Nodes.Nodes
            MsgBox(n.Text)
        Next
I tried to make this property the default property, however I got an error saying that a default property must have a parameter.

I don't know why I'm not getting the same form of:
Code:
        For Each dt As DataTable In myDS.Tables
            ' some code...
        Next
YOURS,
Reply With Quote
  #12  
Old 06-29-2008, 08:49 PM
AtmaWeapon's Avatar
AtmaWeaponGenerating Diagrams From Data AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

In order for a type to support a For Each loop, it must implement IEnumerable. You could go to all that trouble, or read my post again and see how to make a collection class that inherits from a generic collection type and not have to implement anything at all.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #13  
Old 06-30-2008, 07:02 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

I see.
Thank you.
YOURS,
Reply With Quote
  #14  
Old 07-01-2008, 08:14 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

I searched the net and found no such example except a C# example that seemed similar but could not convert it. I don't know even what the best keyword is to write for a search in this case.
Will I ask too much, AtmaWeapon, if I ask you to write such a class, or point me to a website where I can find one?
YOURS,
Reply With Quote
  #15  
Old 07-01-2008, 08:26 AM
darkforcesjedi's Avatar
darkforcesjediGenerating Diagrams From Data darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

The code that AtmaWeapon posted in #10 is everything you need to create an enumerable collection! When you put the line "Inherits Collection(Of Type)" in a class, that class gains all the functionality of the generic Collection, including its enumerability. Create a new class like this:

Code:
Public Class MyCollection
    Inherits Collection(Of Integer)

    Public Sub AdditionalMethod()
        ' this collection does everything that the generic collection does
        ' but it also has this additional method
    End Sub
End Class
Do some research on inheritance in vb.net. This should get you started:
http://www.informit.com/articles/article.aspx?p=170719
__________________
To err is human; to debug, divine.
Reply With Quote
  #16  
Old 07-01-2008, 08:52 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

What is strange since yesterday is that it always gives me an error in the Class header saying:
'Microsoft.VisualBasic.Collection' has no type parameters and so cannot have type arguments.
There is a line under the word "Node" in this line:
Code:
Inherits Collection(Of Node)
Thank you.
Reply With Quote
  #17  
Old 07-01-2008, 09:06 AM
darkforcesjedi's Avatar
darkforcesjediGenerating Diagrams From Data darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

You're using the wrong collection.

System.Collections.ObjectModel.Collection - Use this
Microsoft.VisualBasic.Collection - Not this
__________________
To err is human; to debug, divine.
Reply With Quote
  #18  
Old 07-01-2008, 09:09 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Thank you darkforcesjedi.
Solved by importing System.Collections.ObjectModel.
YOURS,
Reply With Quote
  #19  
Old 07-01-2008, 09:30 AM
Adel99 Adel99 is offline
Centurion
 
Join Date: Aug 2005
Posts: 160
Default

Thank you so much.
Now I have it all done.
YOURS,
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data Generating Diagrams From Data
Generating Diagrams From Data
Generating Diagrams From Data
 
Generating Diagrams From Data
Generating Diagrams From Data
 
-->