Hello. I am trying to get a chart to display a chart image inside a gridview. This image will be populated with data relating to the particular row. The image currently shows but all series collections will not appear and the image is showing data that only relates to the last row bound to the gridview. I have posted my code below. If someone see the issue, please let me know. My thanks in advance for any help.
<asp:TemplateField HeaderText= "Chart" HeaderStyle-ForeColor="Blue" ControlStyle-Font-Size="Large">
<ItemTemplate>
<asp:Chart ID="Chart1" BackColor="LightGray" Width="500" Height = "150" ImageType="Png" runat="server">
</asp:Chart>
</ItemTemplate>
</asp:TemplateField>
Protected Sub gvQuestionResults_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvQuestonResults.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim QID As Integer = 0
QID = CInt(gvQuestonResults.DataKeys(e.Row.RowIndex).Value)
Dim dt As New DataTable
dt = CreateDataTable(QID) 'Builds/populates a datatable based on questionid
'Add the datatable to a dataview and sort
Dim dv As DataView = New DataView(dt)
dv.Sort = "Count desc"
'***Chart Logic***'
Dim chart As Chart
chart = CType(e.Row.FindControl("Chart1"), DataVisualization.Charting.Chart)
chart.ImageStorageMode = ImageStorageMode.UseImageLocation
chart.ImageLocation = "~/tempImages/"
chart.ChartAreas.Add("crtArea")
chart.Legends.Add("crtArea")
For Each Ans As DataRowView In dv 'loop through the dv
Dim li As New LegendItem
Dim seriesName As String = ""
seriesName = CStr(Ans.Item(0))
chart.Series.Add(seriesName)
li.Name = seriesName
Dim len As Integer = 0
len = CInt(CStr(Ans.Item(2)).Length) 'Percentage string length
chart.Series(seriesName).ChartType = SeriesChartType.Area
chart.Series(seriesName).XValueType = ChartValueType.String
chart.Series(seriesName).YValueType = ChartValueType.Int32
chart.Series(seriesName).ChartType = SeriesChartType.Column
chart.Series(seriesName).IsValueShownAsLabel = True
chart.Series(seriesName)("PointWidth") = "0.5"
chart.Series(seriesName)("BarLabelStyle") = "Center"
chart.Series(seriesName)("DrawingStyle") = "Cylinder"
Dim Percentage As String = ""
Percentage = Left(CStr(Ans.Item(2)), len - 1) 'strip off the %
chart.Series(seriesName).Points.AddXY(seriesName, Percentage)
Next
dt.Dispose()
dv.Dispose()
End If
End Sub