Those of you who have taken a look at the new chart controls might have seen that there are multiple ways of rendering these in ASP.NET.
Since my apps (ajax based, no updatepanels etc) use generic httpHandlers for these kind of things, I went looking for the ‘httphandler way’ of rendering the chart controls – but it does not exist..
So I whipped out reflector and took a look at the chart class, and found the three lines needed for doing this
Imports System.Web
Imports System.Web.Services
Imports System.Web.UI.DataVisualization.Charting
Imports System.IO
Public Class chart
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'create the chart
Dim ch As New System.Web.UI.DataVisualization.Charting.Chart
ch.ID = "chart"
ch.Height = 296
ch.Width = 412
ch.ImageType = DataVisualization.Charting.ChartImageType.Png
ch.Palette = DataVisualization.Charting.ChartColorPalette.BrightPastel
ch.BackColor = Drawing.Color.Azure
ch.RenderType = DataVisualization.Charting.RenderType.BinaryStreaming
ch.BorderlineDashStyle = DataVisualization.Charting.ChartDashStyle.Solid
ch.BackGradientStyle = DataVisualization.Charting.GradientStyle.TopBottom
ch.BorderlineWidth = 2
ch.BorderlineColor = Drawing.Color.Blue
ch.BorderSkin.SkinStyle = BorderSkinStyle.Emboss
Dim ser As System.Web.UI.DataVisualization.Charting.Series = ch.Series.Add("Series1")
ser.ChartType = DataVisualization.Charting.SeriesChartType.SplineArea
ser.BorderColor = Drawing.Color.CadetBlue
ser.ShadowOffset = 2
ser.Points.Add(New DataPoint() With {.YValues = New Double() {6}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {9}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {3}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {5}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {2}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {7}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {8}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {1}})
Dim ca = ch.ChartAreas.Add("Default")
ca.BackColor = Drawing.Color.Transparent
ca.BorderColor = Drawing.Color.Red
ca.AxisX.IsMarginVisible = False
context.Response.ContentType = "image/png"
context.Response.Charset = ""
'here comes the magic
Dim imageStream As New MemoryStream
ch.SaveImage(imageStream)
context.Response.BinaryWrite(imageStream.GetBuffer)
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
My name is Øyvind Sean Kinsey and I am currently a software engineer at