Results 1 to 18 of 18

Thread: [RESOLVED] Newbie to VB.NET - and getting data into Chart Control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Resolved [RESOLVED] Newbie to VB.NET - and getting data into Chart Control

    Hi there,

    After many years of putting it off, I have eventually succumbed to the need to transition from VB6 to VB.NET, and am in the early stages of making that transition (with VS 2019). On the basis of looking at examples, following my nose and 'trial and error', I'm not doing too badly, but the exercise is not helped by the fact that I'm struggling a bit to find ideal reading about 'the basics' (which I am currently muddling through) and decent reference material - does anyone have any suggestions about that?

    However, in addition to my 'self-learning, I'm sure that that I'm probably going to need a fair bit of 'spoon feeding' with assistance as well - and the following is one example of that....

    ... there appear to be umpteen ways (some more complicated than others) of getting data (to be plotted) into a Chart control, so I wonder if someone can suggest (ideally 'illustrate') what is the simplest/best method of achieving this when the data exits in the form of an array, or arrays? Many thanks.

    Kind Regards, John

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Newbie to VB.NET - and getting data into Chart Control

    Assuming WinForms, the logical place to start seems to be the documentation for the relevant namespace:

    https://docs.microsoft.com/en-us/dot...tframework-4.8

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by jmcilhinney View Post
    Assuming WinForms, the logical place to start seems to be the documentation for the relevant namespace:
    <link>
    Thanks (and your assumption is correct).

    As you can probably appreciate, for a person in my position a very long list of the 'Classes, Interfaces and Enums' (with no example code) does not make it very easy for me to ascertain the answer to the question I posed (or to implement what I want to do).

    Kind Regards, John

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    duplicate post deleted

  5. #5
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Newbie to VB.NET - and getting data into Chart Control

    Yes there are lots of ways. The best one is the one you know how to do that gives the result you want.

    Based on what you know? here is a way to use an array. Whether is the "best" is debatable.

    We can probably show you "better ways" to make the same graph. Starting with don't use an array use a list.

    Name:  a.png
Views: 6330
Size:  17.1 KB

    Code:
    Imports System.Windows.Forms.DataVisualization.Charting
    Public Class Form3
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Text = "Sample Chart"
            Chart1.Dock = DockStyle.Fill
    
            'make an array
            Dim MyArray(9) As Double
            For x As Integer = 0 To 9
                MyArray(x) = 0.3 * x ^ 1.5
            Next
    
            'setup the chart
            With Chart1.ChartAreas(0)
                .AxisX.Title = "X"
                .AxisX.MajorGrid.LineColor = Color.LightBlue
                .AxisX.Minimum = 0
                .AxisX.Interval = 2
                .AxisY.Title = "Y"
                .AxisY.MajorGrid.LineColor = Color.LightGray
                .AxisY.Minimum = 0
                .BackColor = Color.FloralWhite
                .BackSecondaryColor = Color.White
                .BackGradientStyle = GradientStyle.HorizontalCenter
                .BorderColor = Color.Blue
                .BorderDashStyle = ChartDashStyle.Solid
                .BorderWidth = 1
                .ShadowOffset = 2
            End With
    
            'draw the chart
            Chart1.Series.Clear()
            Chart1.Series.Add("Y = f(x)")
            With Chart1.Series(0)
                .ChartType = DataVisualization.Charting.SeriesChartType.Line
                .BorderWidth = 1
                .Color = Color.Red
                .BorderDashStyle = ChartDashStyle.Dash
                .MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
                .MarkerSize = 4
    
                Dim y As Single
    
                For x As Integer = 0 To MyArray.Length - 1
                    .Points.AddXY(x, MyArray(x))
                Next
            End With
        End Sub
    End Class

  6. #6
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Newbie to VB.NET - and getting data into Chart Control

    PS Almost forgot!

    Here is a project in c# you open and run in the Visual Studio. It shows pictures and examples of most of the things. Its the best doc there is IMHO.

    https://code.msdn.microsoft.com/Samp...s-for-b01e9c61



    Plus this is much improved lately:

    https://docs.microsoft.com/en-us/dot...ramework-4.7.2

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by JohnW2 View Post
    I'm struggling a bit to find [...] decent reference material
    I just provided you a link to THE reference material. If you're not prepared to make the effort to read it because it might be hard then that's your prerogative. If you do make a bit of an effort, you'll see that the Chart class is the heart of it all and the documentation for that points to the Series and ChartArea classes as being critical. Reading about those will lead to more important information. Etc.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by tommytwotrain View Post
    Yes there are lots of ways. The best one is the one you know how to do that gives the result you want.
    I couldn't agree more - but that obviously doesn't work when one has not yet got any experience of doing it any way

    Quote Originally Posted by tommytwotrain View Post
    Based on what you know? here is a way to use an array. Whether is the "best" is debatable.
    Many thanks. That looks pretty straightforward and a very good starting point for me to so some playing (which may result in some follow-up questions!).

    Quote Originally Posted by tommytwotrain View Post
    We can probably show you "better ways" to make the same graph. Starting with don't use an array use a list.
    I suspected that someone might say that. The fact is that my data is 'necessarily' (well, most easily) generated by processing and manipulation of a (multi-dimensional) array. Would the resulting 'benefits' make it worthwhile to turning it into something else before using it for Chart?

    Kind Regards, John

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by tommytwotrain View Post
    PS Almost forgot! ...Here is a project in c# you open and run in the Visual Studio. It shows pictures and examples of most of the things. Its the best doc there is IMHO. <link> ... Plus this is much improved lately: <link>
    Again, many thanks - at a quick glance both of those look as if they might be very useful.

    Kind Regards, John

  10. #10
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by jmcilhinney View Post
    I just provided you a link to THE reference material. If you're not prepared to make the effort to read it because it might be hard then that's your prerogative. If you do make a bit of an effort, you'll see that the Chart class is the heart of it all and the documentation for that points to the Series and ChartArea classes as being critical. Reading about those will lead to more important information. Etc.
    Just info I did not click your link jmc. I looked and thought it was a link to more general .net something. I was planning to show the docs for chart I like and then remembered the ms docs and added that. Now I see I used the same as yours after I focused on the abbreviation the forum made to the link!

    So, long story, abbreviating the links how the forum does has that disadvantage. Nit pick I guess..

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by jmcilhinney View Post
    I just provided you a link to THE reference material. If you're not prepared to make the effort to read it because it might be hard then that's your prerogative. ...
    I'm grateful to you for having identified the reference material, but perhaps I was nor clear. When one is at my stage of the learning curve, reference material only becomes relevant/useful once one 'knows to look up' - otherwise it's like trying to look up a word in a dictionary or encyclopedia when one doesn't know what the word is (and one rarely has time to 'read the whole book'!).

    Kind Regards, John

  12. #12
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by JohnW2 View Post
    I suspected that someone might say that. The fact is that my data is 'necessarily' (well, most easily) generated by processing and manipulation of a (multi-dimensional) array. Would the resulting 'benefits' make it worthwhile to turning it into something else before using it for Chart?
    Oh. Well it just depends. I just added in the list for fun.

    I think you can almost go back and forth as reqd ie MyList.toArray or something.

    But also you can.... link.... no... whats the word ... here we go:

    Code:
              .Points.DataBindXY(Dx, Dy)
    but, if an array is fast then what I show will be just as fast. In fact adding binding prob slows it? Or not. The chart can be very fast sometimes. There is the fastline style also which I have tested and...

    and on and on...


    PS Most of the time you need to do it both ways to find out until you learn it and even then...

    Plus, if it is an issue, some arrays use less memory than other lists etc.
    Last edited by tommytwotrain; Oct 5th, 2019 at 12:41 PM.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by tommytwotrain View Post
    Oh. Well it just depends. I just added in the list for fun. ... I think you can almost go back and forth as reqd ie MyList.toArray or something. ... But also you can.... link.... no... whats the word ... here we go: ...
    Fair enough. In any event ...

    Quote Originally Posted by tommytwotrain View Post
    ... but, if an array is fast then what I show will be just as fast. In fact adding binding prob slows it? Or not. The chart can be very fast sometimes. There is the fastline style also which I have tested and... and on and on ... Plus, if it is an issue, some arrays use less memory than other lists etc.
    In contrast with some of the data I deal with in other contexts (sometimes 'millions of rows of data'), the sets of data being passed to Chart will be truly tiny - so neither speed nor memory usage will be an issue. All I really need is code that works and is relatively easy to create, even if it is not 'optimal', 'efficient' or particularly sophisticated!

    Thanks again for your input - but I can't promise that there won't be further questions once I get my teeth into this!

    Kind Regards, John

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by tommytwotrain View Post
    .... here is a way to use an array. Whether is the "best" is debatable.
    Thanks again. Just to update you as to where I have got to with your help ...

    ... starting with your code and adding some intuition, guesswork, trial and error and some resort to 'the documentation', I now have data provided by multi-dimensional arrays producing various sets of overlaid plots, in some cases with varying 'type' of plot and in all cases with customisation of both the chart as a whole and the plots of individual 'series'. I am now playing to familiarise myself with what other 'tweaking is possible.

    Returning to the issue of 'the documentation' ... the structure (and, indeed, vocabulary) of both VB,NET itself and the MS documentation (and probably any other equivalent of that documentation) is sufficiently complex, and often fairly 'non-intuitive', that for a person in my position (not yet being very familiar with that structure and vocabulary etc.), it can be quite a mission to 'find things'.

    It must have taken me 10 or 15 minutes, maybe longer, to discover what was available for controlling the behaviour and appearance of a chart, and of 'series' presented in that chart (i.e. essentially what I would regard as the Properties of the Chart Control - or, at least of a 'Series' associated with that Chart Control). I eventually found most of what I wanted under "Properties" in ...

    docs / .NET / .NET API Browser / System.System.Forms.DataVisualization.Charting / ChartArea / ChartArea (Class)

    Maybe I'm just dim, but I do not regard that as particularly intuitive, particularly for someone who in not 'in the know'! In an analogous situation with VB, I would expect to find what I needed under something like ...

    VB / Controls /Chart Control /Properties

    .. which I would regard as not only much simpler, but also far more intuitive for anyone who might be looking for such information without much prior experience!

    However, I'm sure that I will gradually (hopefully quite rapidly) get used to all this stuff

    Kind Regards, John

  15. #15
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Newbie to VB.NET - and getting data into Chart Control

    John,

    Yeah.

    Well we have all experienced that. I tell folks go slow learn one thing at a time. Run it, debug it, improve it, add to the next thing.

    It takes time to learn how MS lays out their docs. You just have to practice.

    Don't forget looking at the properties in VS and using F1 help key.

    Also, they all follow the basic pattern so as you learn the docs for one control you see that same layout in all controls more or less. And begin to discover how its done.

    Sometimes you just need one word or bit of code to track to the doc with the answer.

    Same for searching. You learn the search that gives a doc ie

    A search with "vb.net msdn chart properties" shows this link:

    https://docs.microsoft.com/en-us/dot...tframework-4.8

    \/ \/ \/ \/ Click this link !!!!!!!!!!!!!! Below \/ \/ \/ \/

    Get the samples enviro and run it you will be glad you did.

    Did I say it has Pictures with source!!!

    Name:  a.png
Views: 5786
Size:  138.7 KB


    PS And did I say run you project or example code ???????????

    The secret for me is to have a running something.

    And a running project to get good feelings from my proud baby of hard work and even have fun!!!

    Dont just sit there looking at a screen full of errors that wont run.

    Make a new project and run the one line of code until you understand it and enjoy it.

    Now we are having fun programming!!!!!
    Last edited by tommytwotrain; Oct 6th, 2019 at 02:52 PM.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by tommytwotrain View Post
    John, Yeah. Well we have all experienced that. I tell folks go slow learn one thing at a time. Run it, debug it, improve it, add to the next thing. It takes time to learn how MS lays out their docs. You just have to practice.
    I'm practising

    Quote Originally Posted by tommytwotrain View Post
    Don't forget looking at the properties in VS and using F1 help key.
    Yes, that I got used to with VB6 (and other things), and it's probably the most valuable way of taking the first step towards finding what one wants.

    Quote Originally Posted by tommytwotrain View Post
    Sometimes you just need one word or bit of code to track to the doc with the answer.
    True - but knowing the appropriate 'one word' to use is often the problem in the early days!

    Quote Originally Posted by tommytwotrain View Post
    Same for searching. You learn the search that gives a doc ie a search with "vb.net msdn chart properties" shows this link: <link>
    In that case, with that search term, I have to agree that the first 'hit' of the search gets one more-or-less to where one wants to be. However, similar to many others, that search finds (at least for me) nearly 117.000 other 'hits', so it's presumably not always going to be quite so easy!

    I have to say that, when struggling to find what I want in the documentation, I often resort to a Google search of a question in plain English ... a search for something like "how to do XYZ with the Chart Control in VB.NET" will often rapidly give me an indication of what word(s) I should be searching for in the documentation!

    One practical problem for me is that I sometimes have to work in environments where there is no Internet access. With VB6 (and most other software I use), it was feasible to have a useful amount of 'local Help' available, but the sheer volume of 'documentation' for much current stuff seems to mean that is no longer feasible/realistic.

    Quote Originally Posted by tommytwotrain View Post
    ...Get the samples enviro and run it you will be glad you did.
    That seems very valuable. I've made a note of it in big writing Thanks!

    Quote Originally Posted by tommytwotrain View Post
    ... And [B]did I say run you project or example code ??????? The secret for me is to have a running something. .... And a running project to get good feelings from my proud baby of hard work and even have fun!!! .... Make a new project and run the one line of code until you understand it and enjoy it. Now we are having fun programming!!!!!
    Indeed so. Over the course of what must now be over 40 years, I've never formally 'learnt' (in an academic sense) about any programming language or environment (or any other software). I've read just enough to discover how to open the software and run a bit of code, have looked at some examples and then fiddled until I was able to write a line or two of code that actually did something when run ... and then followed my nose from there.

    It doesn't usually take that long for one to develop a usable amount of 'proficiency' - but, as everything gets so much more complex ('versatile', 'better') I presume that no-one is ever going to discover and understand everything, so we all probably press on using 'less than optimal' practices (more 'less optimal' for some of us than others!)! However, as I said before, I'm very pragmatic - and am usually satisfied if my efforts result in something which does what I need (at a sensible speed)!

    ======================

    On a totally different issue, being new to here, I wonder what are the attitudes/etiquettes associated with this forum. I'm sure that there will be lots of little detail questions I'll have which I could answer for myself if I expended sufficient time and energy, but which others might be able to answer simply and immediately id I asked them here. Is the 'lazy' asking of questions in that fashion regarded as 'acceptable' here (or will I keep being told to 'RTFM'? ) - and, if so, is the accepted/preferred practice to start a new thread for each and every little question, or is it acceptable to have an ongoing series of (quite possibly 'unrelated') little questions in one thread?

    Kind Regards, John

  17. #17
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: Newbie to VB.NET - and getting data into Chart Control

    With regard to etiquette (and I am in the same boat as you with regard to my transition from VB6 to VB.NET (partly shown here http://www.vbforums.com/showthread.p...gs-Enhancement) - and I have just built my first working .NET version of the same program - the rule of thumb here seems to be that you need to show you have done some research and looked already into possible solutions.

    There are some here that it takes a while to get the best from, the VB6 part of the forum is like that especially, they don't suffer fools (or each other when they think they are fools) gladly. Don't be put off. I have found this forum to be one of the best resources and the best places to find solutions.

    I often prefix my google searches with "vbforum" as the answer is most often already here.

    The VB.netters are often frustrated by the backwardness of the VB6ers and our archaic way of doing things. You'll see if you visit the VB6 part of the forum that VB6 can do anything that VB.NET can do and the VB6ers strongly defend their corner (quite rightly so).

    The VB.netters I have experienced so far have been a very friendly crowd and many of the VB.netters started off from the same place you did. I include myself as a VB6er until I get this .NET thing firmly under my belt.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2017
    Location
    Buckingham, UK
    Posts
    260

    Re: Newbie to VB.NET - and getting data into Chart Control

    Quote Originally Posted by yereverluvinuncleber View Post
    ... (and I am in the same boat as you with regard to my transition from VB6 to VB.NET) ....
    Interesting - although I'm sure that we are far from alone!

    Quote Originally Posted by yereverluvinuncleber View Post
    ... the rule of thumb here seems to be that you need to show you have done some research and looked already into possible solutions.
    That's how it is in most forums, those who do not do that often being accused of being 'lazy' or even 'parasitic'! It's interesting how that differs from 'the real world', but maybe it's at least partially because the people being asked are generally 'strangers'. If I am in an office and within shouting distance of a colleague, if either of us needs to know something, we will commonly ask "do you happen to know XYZ?". Whilst both of us are probably capable of finding the answer for ourselves, we both recognise that if a colleague can give an instant answer, that is 'more efficient' than spending time (maybe a minute or three, maybe more) hunting for the answer ourselves!

    Quote Originally Posted by yereverluvinuncleber View Post
    There are some here that it takes a while to get the best from, the VB6 part of the forum is like that especially, they don't suffer fools (or each other when they think they are fools) gladly. Don't be put off. I have found this forum to be one of the best resources and the best places to find solutions.
    Yes, I know - although I've rarely had the need to ask anything, I've been 'lurking' in the VB6 part for a couple of years. However, what you describe is at least partly true of any of the forums in which I participate!

    Quote Originally Posted by yereverluvinuncleber View Post
    The VB.netters are often frustrated by the backwardness of the VB6ers and our archaic way of doing things. You'll see if you visit the VB6 part of the forum that VB6 can do anything that VB.NET can do and the VB6ers strongly defend their corner (quite rightly so).
    Yes, I'm aware of that, too. VB6 can be made to do virtually everything I want to do, although VB.NET has a lot more intrinsic capabilities (hence can probably do things better/more easily), but only once one has properly got one's head around it (which, understandably, is more of an exercise than is becoming proficient with VB6). However, presumably like you, after many years of resisting the change, I am now, for one reason or another, in some senses being 'forced' to make the transition.

    Quote Originally Posted by yereverluvinuncleber View Post
    I include myself as a VB6er until I get this .NET thing firmly under my belt.
    I suppose it's the same with me!

    Kind Regards, John

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