Michael Freundorfer Michael Freundorfer - 1 year ago 68
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"

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


For Each dr As DataRow In dt.Rows
Dim dp As New DataPoint
dp.AxisLabel = CStr(dr.Item("Datum"))

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)

<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=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

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

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

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

Answer Source

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>