I have a SQL database that I use, tor the information within my chart. The SQL query populates 5 gridview controls for each week. Each Gridview control contains Total amount and the weekday name. I populate the charts series from each gridview. The X axis is set for the weekdays and the Y axis is set for the Total amt. Each week starts with Sunday except the first week. The first week can start with any day depending on the month. When the chart is populated it maps every series to the first day of week 1. For example, if week 1 falls on a Tuesday it will plot every data point on Tuesday even if it's a Sunday,Monday, etc. My question is, how can I get the datapoints to plot to the correct day/total? BTW I'm using a line chart. See how week 1 falls on Sunday even though it starts with Tuesday.
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedIndex = 0 Then
Label1.Text = "01/31/11"
ElseIf DropDownList1.SelectedIndex = 1 Then
Label1.Text = "02/28/11"
ElseIf DropDownList1.SelectedIndex = 2 Then
Label1.Text = "03/31/11"
ElseIf DropDownList1.SelectedIndex = 3 Then
Label1.Text = "04/30/11"
ElseIf DropDownList1.SelectedIndex = 4 Then
Label1.Text = "05/31/11"
ElseIf DropDownList1.SelectedIndex = 5 Then
Label1.Text = "06/30/11"
ElseIf DropDownList1.SelectedIndex = 6 Then
Label1.Text = "07/31/11"
ElseIf DropDownList1.SelectedIndex = 7 Then
Label1.Text = "08/31/11"
ElseIf DropDownList1.SelectedIndex = 8 Then
Label1.Text = "09/30/11"
ElseIf DropDownList1.SelectedIndex = 9 Then
Label1.Text = "10/31/11"
ElseIf DropDownList1.SelectedIndex = 10 Then
Label1.Text = "11/30/11"
ElseIf DropDownList1.SelectedIndex = 11 Then
Label1.Text = "12/31/11"
End If
End Sub
Private Sub GridView1_PreRender(sender As Object, e As System.EventArgs) Handles GridView1.PreRender
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Format = "{0:c}"
Dim Description As String = CType(Session.Item("field3"), String)
For Each d As GridViewRow In GridView1.Rows
If d.Cells(1).Text = "$0.00" Then
d.Cells(0).Visible = False
d.Cells(1).Visible = False
End If
Next
Dim t1 As New System.Web.UI.DataVisualization.Charting.Title
t1.Text = Description & " - " & DropDownList1.Text & " - " & DropDownList1.SelectedItem.Text
t1.Font = New System.Drawing.Font("Verdana", 20, Drawing.FontStyle.Italic)
Chart1.Titles.Insert(0, t1)
Chart1.Series.Add("Week1")
Chart1.Series("Week1").BorderWidth = "5"
Chart1.Series("Week1").IsXValueIndexed = False
Chart1.Series("Week1").MarkerColor = Drawing.Color.Black
Chart1.Series("Week1").MarkerSize = "5"
Chart1.Series("Week1").MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
'Chart1.Series("Week1").IsValueShownAsLabel = True
Chart1.Series("Week1").YValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week1").XValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week1").ChartType = DataVisualization.Charting.SeriesChartType.Line
For Each d As GridViewRow In GridView1.Rows
If d.Cells(1).Text > "$0.00" Then
Chart1.Series("Week1").Points.AddXY("", d.Cells(1).Text)
End If
Next
End Sub
Private Sub GridView2_PreRender(sender As Object, e As System.EventArgs) Handles GridView2.PreRender
For Each d As GridViewRow In GridView2.Rows
If d.Cells(1).Text = "$0.00" Then
d.Cells(0).Visible = False
d.Cells(1).Visible = False
End If
Next
Chart1.Series.Add("Week2")
Chart1.Series("Week2").BorderWidth = "5"
Chart1.Series("Week2").IsXValueIndexed = False
Chart1.Series("Week2").MarkerColor = Drawing.Color.Black
Chart1.Series("Week2").MarkerSize = "5"
Chart1.Series("Week2").MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
'Chart1.Series("Week1").IsValueShownAsLabel = True
Chart1.Series("Week2").YValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week2").XValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week2").ChartType = DataVisualization.Charting.SeriesChartType.Line
For Each d1 As GridViewRow In GridView2.Rows
If d1.Cells(1).Text > "$0.00" Then
Chart1.Series("Week2").Points.AddXY(d1.Cells(0).Text, d1.Cells(1).Text)
End If
Next
End Sub
Private Sub GridView3_PreRender(sender As Object, e As System.EventArgs) Handles GridView3.PreRender
For Each d As GridViewRow In GridView3.Rows
If d.Cells(1).Text = "$0.00" Then
d.Cells(0).Visible = False
d.Cells(1).Visible = False
End If
Next
Chart1.Series.Add("Week3")
Chart1.Series("Week3").BorderWidth = "5"
Chart1.Series("Week3").IsXValueIndexed = False
Chart1.Series("Week3").MarkerColor = Drawing.Color.Black
Chart1.Series("Week3").MarkerSize = "5"
Chart1.Series("Week3").MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
'Chart1.Series("Week1").IsValueShownAsLabel = True
Chart1.Series("Week3").YValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week3").XValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week3").ChartType = DataVisualization.Charting.SeriesChartType.Line
For Each d1 As GridViewRow In GridView3.Rows
If d1.Cells(1).Text > "$0.00" Then
Chart1.Series("Week3").Points.AddXY(d1.Cells(0).Text, d1.Cells(1).Text)
End If
Next
End Sub
Private Sub GridView4_PreRender(sender As Object, e As System.EventArgs) Handles GridView4.PreRender
For Each d As GridViewRow In GridView4.Rows
If d.Cells(1).Text = "$0.00" Then
d.Cells(0).Visible = False
d.Cells(1).Visible = False
End If
Next
Chart1.Series.Add("Week4")
Chart1.Series("Week4").BorderWidth = "5"
Chart1.Series("Week4").IsXValueIndexed = False
Chart1.Series("Week4").MarkerColor = Drawing.Color.Black
Chart1.Series("Week4").MarkerSize = "5"
Chart1.Series("Week4").MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
'Chart1.Series("Week1").IsValueShownAsLabel = True
Chart1.Series("Week4").YValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week4").XValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week4").ChartType = DataVisualization.Charting.SeriesChartType.Line
For Each d1 As GridViewRow In GridView4.Rows
If d1.Cells(1).Text > "$0.00" Then
Chart1.Series("Week4").Points.AddXY(d1.Cells(0).Text, d1.Cells(1).Text)
End If
Next
End Sub
Private Sub GridView5_PreRender(sender As Object, e As System.EventArgs) Handles GridView5.PreRender
For Each d As GridViewRow In GridView5.Rows
If d.Cells(1).Text = "$0.00" Then
d.Cells(0).Visible = False
d.Cells(1).Visible = False
End If
Next
Chart1.Series.Add("Week5")
Chart1.Series("Week5").BorderWidth = "5"
Chart1.Series("Week5").IsXValueIndexed = False
Chart1.Series("Week5").MarkerColor = Drawing.Color.Black
Chart1.Series("Week5").MarkerSize = "5"
Chart1.Series("Week5").MarkerStyle = DataVisualization.Charting.MarkerStyle.Square
'Chart1.Series("Week1").IsValueShownAsLabel = True
Chart1.Series("Week5").YValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week5").XValueType = DataVisualization.Charting.ChartValueType.Auto
Chart1.Series("Week5").ChartType = DataVisualization.Charting.SeriesChartType.Line
For Each d1 As GridViewRow In GridView5.Rows
If d1.Cells(1).Text > "$0.00" Then
Chart1.Series("Week5").Points.AddXY(d1.Cells(0).Text, d1.Cells(1).Text)
End If
Next
End Sub