Murray Brown
asked on
ASP.net Chart generation causes server error
Hi
I am using the following code to generate a chart on the timer tick. All works fine in debugging but it crashes on line and I get the error shown below. I also ran the timer tick without the oAdd_Random_Chart() call and it caused the error. So it looks like the timer tick as the main problem
Image1.jpg
I am using the following code to generate a chart on the timer tick. All works fine in debugging but it crashes on line and I get the error shown below. I also ran the timer tick without the oAdd_Random_Chart() call and it caused the error. So it looks like the timer tick as the main problem
Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
oAdd_Random_Chart()
End Sub
Sub oAdd_Random_Chart()
' Initialize the Chart object
Dim chart1 As New Chart()
chart1.ID = "chart1"
'Add to do code here
' Initialize objects and elements
Dim chartArea1 As New ChartArea()
Dim legend1 As New Legend()
Dim series1 As New Series()
Dim series2 As New Series()
Dim series3 As New Series()
Dim series4 As New Series()
Dim series5 As New Series()
' Set the Chart Properties
chart1.Width = 900
chart1.Height = 340
chart1.BackColor = System.Drawing.Color.Navy
chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
chart1.BorderlineColor = System.Drawing.Color.Gray
'chart1.BorderLineStyle = ChartDashStyle.Solid
chart1.BorderlineWidth = 4
chart1.BackGradientStyle = GradientStyle.LeftRight
' Set the ChartArea properties
chartArea1.Name = "Default"
chartArea1.BackColor = System.Drawing.Color.SlateGray
chartArea1.BackGradientStyle = GradientStyle.LeftRight
'Enable AJAX features such as zooming and scrolling for the ChartArea
'chartArea1.CursorX.UserEnabled = True
'chartArea1.CursorY.UserEnabled = True
' Add the ChartArea to the Chart
chart1.ChartAreas.Add(chartArea1)
' Set the Legend properties
legend1.Name = "Default"
legend1.Docking = Docking.Bottom
legend1.LegendStyle = LegendStyle.Row
legend1.Alignment = System.Drawing.StringAlignment.Center
legend1.BackColor = System.Drawing.Color.Transparent
legend1.BorderColor = System.Drawing.Color.Black
legend1.BorderWidth = 1
' Add the Legend to the Chart
chart1.Legends.Add(legend1)
' Set the Series properties
series1.Name = "Store 1"
series1.ChartType = SeriesChartType.Line
series1.BorderColor = Drawing.Color.Black
series1.BorderWidth = 3
'following two lines used to change series line colors....
series1.EmptyPointStyle.Color = Drawing.Color.Transparent
series1.Color = Drawing.Color.DodgerBlue
series2.Name = "Store 2"
series2.BorderColor = System.Drawing.Color.DarkSlateGray
series2.BorderWidth = 3
series2.ChartType = SeriesChartType.Line
'following two lines used to change series line colors....
series2.EmptyPointStyle.Color = Drawing.Color.Transparent
series2.Color = Drawing.Color.Green
series3.Name = "Store 3"
series3.BorderWidth = 3
series3.ChartType = SeriesChartType.Line
'following two lines used to change series line colors....
series3.EmptyPointStyle.Color = Drawing.Color.Transparent
series3.Color = Drawing.Color.Red
series4.Name = "Store 4"
series4.BorderWidth = 3
series4.ChartType = SeriesChartType.Line
'following two lines used to change series line colors....
series4.EmptyPointStyle.Color = Drawing.Color.Transparent
series4.Color = Drawing.Color.Olive
series5.Name = "Store 5"
series5.BorderWidth = 3
series5.ChartType = SeriesChartType.Line
'following two lines used to change series line colors....
series5.EmptyPointStyle.Color = Drawing.Color.Transparent
series5.Color = Drawing.Color.MintCream
' Add the Series to the Chart
chart1.Series.Add(series1)
chart1.Series.Add(series2)
chart1.Series.Add(series3)
chart1.Series.Add(series4)
chart1.Series.Add(series5)
' Add points to each series.
Dim rnd As New Random()
Dim S As String = "Laptops,Desktops,Cameras,Smart Phones,Phones,Batteries,Computer Bags,Camera Bags,Accessories,Airtime,Modems,Memory Sticks,3g USB Modems"
Dim arrSplit As Object = Split(S, ",")
Dim oNewRandomNumber As String
For Each ser As Series In chart1.Series
For i As Integer = 0 To 12
'ser.Points.AddY(rnd.[Next](5, 10))
oNewRandomNumber = rnd.[Next](0, 100)
If ser.Name = "Store 1" Then
oNewRandomNumber = oNewRandomNumber * 0.5
ElseIf ser.Name = "Store 2" Then
oNewRandomNumber = oNewRandomNumber * 0.7
ElseIf ser.Name = "Store 3" Then
oNewRandomNumber = oNewRandomNumber * 0.9
ElseIf ser.Name = "Store 4" Then
oNewRandomNumber = oNewRandomNumber * 0.3
ElseIf ser.Name = "Store 5" Then
oNewRandomNumber = oNewRandomNumber * 0.6
End If
ser.Points.AddXY(arrSplit(i), oNewRandomNumber)
Next
Next
Dim oTitle As String = "Sales Activity Across Stores"
chart1.Titles.Add(New Title(oTitle, Docking.Top, New Font("Century Gothic", 13, FontStyle.Regular), Drawing.Color.White))
'Preserve the chart's state during callbacks
'chart1.CallbackStateContent = CallbackStateContent.All
Me.Panel1.Controls.Add(chart1)
End Sub
Image1.jpg
That URL does not look right. Does the page navigate to that URL automatically?
ASKER
Hi. Yes it navigates there automatically
ASKER
Hi. I finally managed to change the web config to show the following error:
Server Error in '/' Application.
Invalid temp images directory in chart handler configuration [c:\TempImageFiles\]. Please edit the web.config file. The CharImageHandler key, Dir value must point to a valid directory. The directory is required for temporary image storage when storage mode equals file system.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoun dException : Invalid temp images directory in chart handler configuration [c:\TempImageFiles\]. Please edit the web.config file. The CharImageHandler key, Dir value must point to a valid directory. The directory is required for temporary image storage when storage mode equals file system.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundExceptio n: Invalid temp images directory in chart handler configuration [c:\TempImageFiles\]. Please edit the web.config file. The CharImageHandler key, Dir value must point to a valid directory. The directory is required for temporary image storage when storage mode equals file system.]
System.Web.UI.DataVisualiz ation.Char ting.Chart HttpHandle rSettings. Inspect() +892964
System.Web.UI.DataVisualiz ation.Char ting.Chart HttpHandle rSettings. ParseParam s(String parameters) +430
System.Web.UI.DataVisualiz ation.Char ting.Chart HttpHandle r.Initiali zeParamete rs() +122
System.Web.UI.DataVisualiz ation.Char ting.Chart HttpHandle r.get_Sett ings() +32
System.Web.UI.DataVisualiz ation.Char ting.Chart HttpHandle r.Initiali zeControll erFile() +25
System.Web.UI.DataVisualiz ation.Char ting.Chart HttpHandle r.EnsureIn itialized( Boolean hardCheck) +461
System.Web.UI.DataVisualiz ation.Char ting.Chart .GetImageS torageMode () +24
System.Web.UI.DataVisualiz ation.Char ting.Chart .get_Curre ntImageLoc ation() +40
System.Web.UI.DataVisualiz ation.Char ting.Chart .Render(Ht mlTextWrit er writer) +302
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.Control.Rend erChildren (HtmlTextW riter writer) +8
System.Web.UI.Control.Rend er(HtmlTex tWriter writer) +10
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.UpdatePanel. RenderChil dren(HtmlT extWriter writer) +243
System.Web.UI.UpdatePanel. Render(Htm lTextWrite r writer) +38
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.Control.Rend erChildren (HtmlTextW riter writer) +8
System.Web.UI.WebControls. WebControl .RenderCon tents(Html TextWriter writer) +10
System.Web.UI.WebControls. WebControl .Render(Ht mlTextWrit er writer) +32
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.Control.Rend erChildren (HtmlTextW riter writer) +8
System.Web.UI.Control.Rend er(HtmlTex tWriter writer) +10
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.HtmlControls .HtmlForm. RenderChil dren(HtmlT extWriter writer) +216
System.Web.UI.HtmlControls .HtmlConta inerContro l.Render(H tmlTextWri ter writer) +32
System.Web.UI.HtmlControls .HtmlForm. Render(Htm lTextWrite r output) +53
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.HtmlControls .HtmlForm. RenderCont rol(HtmlTe xtWriter writer) +40
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.Control.Rend erChildren (HtmlTextW riter writer) +8
System.Web.UI.Control.Rend er(HtmlTex tWriter writer) +10
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Control.Rend erChildren Internal(H tmlTextWri ter writer, ICollection children) +128
System.Web.UI.Control.Rend erChildren (HtmlTextW riter writer) +8
System.Web.UI.Page.Render( HtmlTextWr iter writer) +29
System.Web.UI.Control.Rend erControlI nternal(Ht mlTextWrit er writer, ControlAdapter adapter) +57
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer, ControlAdapter adapter) +100
System.Web.UI.Control.Rend erControl( HtmlTextWr iter writer) +25
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +1386
Server Error in '/' Application.
Invalid temp images directory in chart handler configuration [c:\TempImageFiles\]. Please edit the web.config file. The CharImageHandler key, Dir value must point to a valid directory. The directory is required for temporary image storage when storage mode equals file system.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoun
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundExceptio
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.DataVisualiz
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.UpdatePanel.
System.Web.UI.UpdatePanel.
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.HtmlControls
System.Web.UI.HtmlControls
System.Web.UI.HtmlControls
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.HtmlControls
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Page.Render(
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Control.Rend
System.Web.UI.Page.Process
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi. I realise it is. I don't want to answer my own question :)