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![]()




Reply With Quote
