|
-
Jan 28th, 2010, 08:39 PM
#1
Thread Starter
Addicted Member
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.
-
Jan 28th, 2010, 09:37 PM
#2
Re: MS Chart and Listview Subitems
 Originally Posted by SavedByGrace
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.
-
Jan 28th, 2010, 09:46 PM
#3
Thread Starter
Addicted Member
Re: MS Chart and Listview Subitems
 Originally Posted by jmcilhinney
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.
-
Jan 28th, 2010, 09:52 PM
#4
Re: MS Chart and Listview Subitems
 Originally Posted by SavedByGrace
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.
-
Jan 28th, 2010, 10:00 PM
#5
Thread Starter
Addicted Member
Re: MS Chart and Listview Subitems
 Originally Posted by jmcilhinney
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.
-
Jan 28th, 2010, 10:20 PM
#6
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.
-
Jan 28th, 2010, 11:18 PM
#7
Thread Starter
Addicted Member
Re: MS Chart and Listview Subitems
 Originally Posted by jmcilhinney
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.
-
Jan 29th, 2010, 02:18 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|