Hello,
I generated a Line Chart in VB.Net, so I need to print it out but I don't know how to print it by a button call "Print"
The following coding for your reference:
Protected Sub btn_Print_Click(sender As Object, e As EventArgs) Handles btn_Print.Click
End Sub
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
dtInt.Rows(row.RowIndex)(i) = row.Cells(i).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 String()
x = (From p In dtInt.AsEnumerable()
Where p.Field(Of String)("Department") = department1
Order By p.Field(Of String)("Period_Shown")
Select 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()
RateChart.Series.Add(New Series(department1))
RateChart.Series(department1).IsValueShownAsLabel = False
RateChart.Series(department1).BorderWidth = 3
RateChart.Series(department1).ChartType = SeriesChartType.Line
RateChart.Series(department1).Points.DataBindXY(x, y)
RateChart.Series(department1).MarkerStyle = MarkerStyle.Star10
Next
RateChart.Legends.Add("Default")
RateChart.Legends(0).Docking = Docking.Right
RateChart.Legends(0).IsTextAutoFit = True
RateChart.Legends(0).Alignment = Drawing.StringAlignment.Center
RateChart.Legends(0).Enabled = True
RateChart.ChartAreas(0).AxisX.Interval = 1
End Sub