Michael Freundorfer Michael Freundorfer - 3 months ago 20
Vb.net Question

Chart for ASP.NET won't get displayed

I'm using the integrated chart control in an aspx-website (.NET 4.0) and I'm not able to get it displayed. Here's my code (VB.NET):

Protected Sub CreateChart(ByVal dt As DataTable, ByVal KZ As DB_Kennzahl)
Dim chart As New Chart
chart.Height = Unit.Pixel(400)
chart.Width = Unit.Pixel(800)

Dim ca As New ChartArea
ca.Name = "ChartArea"
chart.ChartAreas.Add(ca)

Dim seriesKZ As New Series
seriesKZ.Name = KZ.Text
seriesKZ.ChartType = SeriesChartType.Column
seriesKZ.Color = Drawing.Color.Blue

chart.Series.Add(seriesKZ)

For Each dr As DataRow In dt.Rows
Dim dp As New DataPoint
dp.SetValueY(Convert.ToDecimal(dr.Item(6)))
dp.AxisLabel = CStr(dr.Item("Datum"))
seriesKZ.Points.Add(dp)
Next

chart.DataBind()
plch_Chart.Controls.Add(chart)
End Sub


As you can see I'm using a table to fill the chart's data.
The chart is added to a simple placeholder.

<asp:PlaceHolder ID="plch_Chart" runat="server" Visible="true"></asp:PlaceHolder>


Did I forget something to write in the code? I can't figure it out what's wrong. The code seems right because not even a single exception will get thrown.

EDIT: Web.config: (Only the parts which are affecting the chart)

<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>

<add key="ChartImageHandler" value="storage=file;timeout=20;Url=~\TempImageFiles\;" />

<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
</httpHandlers>

<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>

Answer

Your web.config seems correct. Instead of adding your control to a place holder, can you create it directly in the page ?

<asp:Chart ID="myChart" runat="server" ImageStorageMode="UseImageLocation" Width="800px" Height="400px" ImageLocation="~/someTempFolder/myChartImage"> <Series> <asp:Series Name="Serie1"></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"></asp:ChartArea> </ChartAreas> </asp:Chart>

Comments