Results 1 to 8 of 8

Thread: MS Chart and Listview Subitems

  1. #1

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    MS Chart and Listview Subitems

    There are very few examples out there for MS Chart and VS 2008 (the ones provided by MS are for a version different than what I have). What I am trying to do is get the value of the subitems in a listview (1 subitem is Subtotal and the other is Shipping) and put them on the chart. I don't know the best way to do this. I managed to get some code to work with a Datagridview but not with a listview. I have pasted the code for the chart with the datagridview below (to make the code run simply add MS Chart, a Datagridview and a button. Also, I posted a screen capture of a listview with the chart to give a better idea of what I am trying to accomplish. Any suggestions or help would be welcome - Thanks.


    Code:
    Imports System.Windows.Forms.DataVisualization.Charting
    Imports System.Globalization
    
    Public Class FrmChartTest
        Dim dtTest As New DataTable
        Dim dsTest As New DataSet
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim lstDays As New List(Of String) '//contains the days/weeks/months/
            lstDays.AddRange(CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames) '//adds days/months etc in short form
    
            dtTest.Reset()
            dsTest.Reset()
            dtTest = dsTest.Tables.Add("dtTest")
    
            dtTest.Columns.Add("Day of Week", GetType(String))
            dtTest.Columns.Add("Site 1", GetType(Integer))
            dtTest.Columns.Add("Site 2", GetType(Integer))
    
            Dim rnd As New Random
            For r As Integer = 0 To 6
                Dim value1 As Integer = rnd.Next(0, 101)
                Dim value2 As Integer = rnd.Next(0, 101)
                dtTest.Rows.Add(lstDays(r), value1, value2)
            Next
    
            Chart1.Series.Clear() '//Clear all series
    
            Chart1.Dock = DockStyle.Bottom
            Chart1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Top
    
    
            Chart1.Series.Add("Site 1") '//Add new Series
            'Chart1.Series(0).IsVisibleInLegend = True
            With Chart1.Series("Site 1")
                .ChartType = SeriesChartType.Spline '= SeriesChartType.Line
                .Name = "Site 1"
                .LegendText = "Site 1"
                .IsVisibleInLegend = True
                .Font = New Font("Arial", 10, FontStyle.Italic)
                .Color = Color.Blue
                .IsValueShownAsLabel = True
                .LabelForeColor = Color.Red
                .Points.DataBind(dtTest.DefaultView, "Day of Week", "Site 1", Nothing)
            End With
    
    
            Chart1.Series.Add("Site 2") '//Add New Series
            With Chart1.Series("Site 2")
                .ChartType = SeriesChartType.Spline
                .Name = "Site 2"
                .LegendText = "Site 2"
                .IsVisibleInLegend = True
                .Font = New Font("Arial", 10, FontStyle.Italic)
                .Color = Color.Coral
                .IsValueShownAsLabel = True
                .LabelForeColor = Color.Green
                .Points.DataBind(dtTest.DefaultView, "Day of Week", "Site 2", Nothing)
            End With
    
            With Chart1.ChartAreas(0)
                .AxisY.Interval = 20
                .AxisX.LabelStyle.Angle = -90
                .AxisX.Title = "Day"
                .AxisY.Title = "Sales"
            End With
        End Sub
    End Class
    Last edited by SavedByGrace; Jan 28th, 2010 at 09:48 PM.

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

    Re: MS Chart and Listview Subitems

    Quote Originally Posted by SavedByGrace View Post
    There are very few examples out there for MS Chart and VS 2008 (the ones provided by MS are for .net).
    Um, VS 2008 IS .NET. Everything since VB6/VS6 is .NET. They simply dropped the .NET suffix from 2005 onwards because .NET was assumed to be the default and anything else would have to be differentiated from that. Every VS/VB version since 2002 is .NET-specific. Every .NET example you've seen for MSChart is relevant to to VS 2008.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Re: MS Chart and Listview Subitems

    Quote Originally Posted by jmcilhinney View Post
    Um, VS 2008 IS .NET. Everything since VB6/VS6 is .NET. They simply dropped the .NET suffix from 2005 onwards because .NET was assumed to be the default and anything else would have to be differentiated from that. Every VS/VB version since 2002 is .NET-specific. Every .NET example you've seen for MSChart is relevant to to VS 2008.
    I realize that, but the examples they have will not open with VS 2008 - "Not supported by this version of Visual Studio"

    Just FYI - I have Visual Studio 6.0, VB 2005 and VB 2008 Express editions.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MS Chart and Listview Subitems

    Quote Originally Posted by SavedByGrace View Post
    I realize that, but the examples they have will not open with VS 2008 - "Not supported by this version of Visual Studio"

    Just FYI - I have Visual Studio 6.0, VB 2005 and VB 2008 Express editions.
    Unless those examples were created in VS 2010, which I very much doubt, then they will open in VS 2008. Perhaps they're C# examples and you're trying to open them in VB Express, or maybe you're trying to open the web examples, which would require VWD Express.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Re: MS Chart and Listview Subitems

    Quote Originally Posted by jmcilhinney View Post
    Unless those examples were created in VS 2010, which I very much doubt, then they will open in VS 2008. Perhaps they're C# examples and you're trying to open them in VB Express, or maybe you're trying to open the web examples, which would require VWD Express.
    That's possible. I pretty much repeated what I saw during my search for examples regarding the compatibility of examples provided by MS - If they are in C# or any other language (except Delphi and php) I wouldn't know where to begin for converting them to VB format - So, I'm still left with the same dilemma.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MS Chart and Listview Subitems

    I just looked here:

    http://code.msdn.microsoft.com/mschart

    and it appears from comments people have left that there were VB samples at some point, which I thought was the case, but the download on the next page only seems to contain C# samples.

    You could always install C# Express and load them in that. The form design will be the same and the code is really not as different as you might think. That's not ideal though. There are code converters around bu most will only convert code snippets rather than whole projects. Instant VB will convert a project but only in the paid-for version; the trial only converts small snippets. I've never tried but I think that SharpDevelop can convert a C# project to VB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Addicted Member SavedByGrace's Avatar
    Join Date
    May 2006
    Posts
    130

    Re: MS Chart and Listview Subitems

    Quote Originally Posted by jmcilhinney View Post
    I just looked here:

    http://code.msdn.microsoft.com/mschart

    and it appears from comments people have left that there were VB samples at some point, which I thought was the case, but the download on the next page only seems to contain C# samples.

    You could always install C# Express and load them in that. The form design will be the same and the code is really not as different as you might think. That's not ideal though. There are code converters around bu most will only convert code snippets rather than whole projects. Instant VB will convert a project but only in the paid-for version; the trial only converts small snippets. I've never tried but I think that SharpDevelop can convert a C# project to VB.
    I appreciate your attempt to help but I think you are missing the point, I merely said "There are very few examples out there for MS Chart and VS 2008" which was more of a statement to imply that I was having a difficult time finding resources that may help me figure out the best way to to get data from an ListView into the graph - I'm looking for advice as to the best way to do this, not examples of MS Charts in general. By the way, I activated my copy of C# a short while ago and the examples MS provided are in C# but they do provide some code for VB inside the parent app - none of which shows how to do what I am trying here. Thanks.

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: MS Chart and Listview Subitems

    There are very few examples out there for MS Chart and VS 2008 (the ones provided by MS are for a version different than what I have).
    Have you checked Gep13's signature. I believe he has a link to a thread with links to examples... Not sure if that is what you want....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

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