Click here to Skip to main content
15,891,778 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
But It seems not work of my chart, 1) X-axis cannot shown right data and Y- Axis is also.

It the problem of my array? it is because Data Type of Period_shown is string?

Here is the source code

What I have tried:

VB
Protected Sub btn_Int_Click(sender As Object, e As EventArgs) Handles btn_Int.Click
      Label001.Visible = False
      Label37.Visible = True
      Label39.Visible = True
      Label48.Visible = True
      Label51.Visible = False
      Label52.Visible = False
      Label37.Text = "The Chart of " & Label38.Text & " by Number of Incidents "
      Label48.Text = "From" & " " & Label42.Text & " " & "to" & " " & Label45.Text
      If DropDownList13.SelectedIndex = -1 Then
          Label39.Text = Label40.Text
      Else
          Label39.Text = Label40.Text & Label41.Text
      End If
      btn_Print.Visible = True
      RateChart.Visible = True
          Dim dtInt As DataTable = New DataTable("dtInts")
          For Each cell As TableCell In gvInt.HeaderRow.Cells
              dtInt.Columns.Add(cell.Text.Trim())
          Next
          For Each row As GridViewRow In gvInt.Rows
              dtInt.Rows.Add()
              For i As Integer = 0 To row.Cells.Count = -1
                  Dim j As Integer = i
                  dtInt.Rows(row.RowIndex)(j) = row.Cells(j).Text.Trim()
              Next
          Next
          Dim departments As List(Of String) = New List(Of String)()
          departments = (From p In dtInt.AsEnumerable() Select p.Field(Of String)("Department")).Distinct().ToList()
          If RateChart.Series.Count() = 1 Then
              RateChart.Series.Remove(RateChart.Series(0))
          End If
          For Each department As String In departments.ToList()
              Dim department1 As String = department
              Dim X As Integer()
              X = (From p In dtInt.AsEnumerable()
                      Where p.Field(Of String)("Department") = department1
                      Order By p.Field(Of String)("Period_Shown")
                      Select Convert.ToInt32(p.Field(Of String)("Period_Shown"))).ToArray()
              Dim Y As Decimal()
              Y = (From p In dtInt.AsEnumerable()
                      Where p.Field(Of String)("Department") = department1
                      Order By p.Field(Of String)("Period_Shown")
                      Select Convert.ToDecimal(p.Field(Of String)("Num_Int"))).ToArray()
              departments.Add(department1)
              RateChart.Series.Add(New Series(department1))
              RateChart.Series(department1).IsValueShownAsLabel = True
              RateChart.Series(department1).BorderWidth = 3
              RateChart.Series(department1).ChartType = SeriesChartType.Line
              RateChart.Series(department1).Points.DataBindXY(X, Y)
          Next
      RateChart.Legends(0).Enabled = True
  End Sub
Posted
Comments
[no name] 4-Dec-20 15:35pm    
How many departments did you retrieve? How many data points per department?
Member 15000241 4-Dec-20 23:29pm    
For department, at least 1 department to 15 departments, not fixed.
For point of department, at least 6 to 108 points.
According to the above coding, Legends can be shown as right department from my selection. but seems cannot put the right data in Y axis.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900