{"id":34,"date":"2008-11-13T16:51:13","date_gmt":"2008-11-13T14:51:13","guid":{"rendered":"http:\/\/kinsey.no\/wp\/?p=34"},"modified":"2009-08-20T17:15:19","modified_gmt":"2009-08-20T15:15:19","slug":"microsoft-chart-controls-for-the-net-framework-rendering-using-a-httphandler","status":"publish","type":"post","link":"https:\/\/kinsey.no\/blog\/index.php\/2008\/11\/13\/microsoft-chart-controls-for-the-net-framework-rendering-using-a-httphandler\/","title":{"rendered":"Microsoft Chart Controls for the .Net Framework &#8211; rendering using a httpHandler"},"content":{"rendered":"<p>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.<\/p>\n<p>Since my apps (ajax based, no updatepanels etc) use generic httpHandlers for these kind of things, I went looking for the &#8216;httphandler way&#8217; of rendering the chart controls &#8211; but it does not exist..<\/p>\n<p>So I whipped out reflector and took a look at the chart class, and found the three lines needed for doing this<br \/>\n<!--more--><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\nImports System.Web\r\nImports System.Web.Services\r\nImports System.Web.UI.DataVisualization.Charting\r\nImports System.IO\r\n\r\nPublic Class chart\r\nImplements System.Web.IHttpHandler\r\n\r\nSub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest\r\n'create the chart\r\nDim ch As New System.Web.UI.DataVisualization.Charting.Chart\r\nch.ID = &amp;quot;chart&amp;quot;\r\nch.Height = 296\r\nch.Width = 412\r\nch.ImageType = DataVisualization.Charting.ChartImageType.Png\r\nch.Palette = DataVisualization.Charting.ChartColorPalette.BrightPastel\r\nch.BackColor = Drawing.Color.Azure\r\nch.RenderType = DataVisualization.Charting.RenderType.BinaryStreaming\r\nch.BorderlineDashStyle = DataVisualization.Charting.ChartDashStyle.Solid\r\nch.BackGradientStyle = DataVisualization.Charting.GradientStyle.TopBottom\r\nch.BorderlineWidth = 2\r\nch.BorderlineColor = Drawing.Color.Blue\r\nch.BorderSkin.SkinStyle = BorderSkinStyle.Emboss\r\n\r\nDim ser As System.Web.UI.DataVisualization.Charting.Series = ch.Series.Add(&amp;quot;Series1&amp;quot;)\r\nser.ChartType = DataVisualization.Charting.SeriesChartType.SplineArea\r\nser.BorderColor = Drawing.Color.CadetBlue\r\nser.ShadowOffset = 2\r\n\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {6}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {9}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {3}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {5}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {2}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {7}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {8}})\r\nser.Points.Add(New DataPoint() With {.YValues = New Double() {1}})\r\n\r\nDim ca = ch.ChartAreas.Add(&amp;quot;Default&amp;quot;)\r\nca.BackColor = Drawing.Color.Transparent\r\nca.BorderColor = Drawing.Color.Red\r\nca.AxisX.IsMarginVisible = False\r\n\r\ncontext.Response.ContentType = &amp;quot;image\/png&amp;quot;\r\ncontext.Response.Charset = &amp;quot;&amp;quot;\r\n\r\n'here comes the magic\r\nDim imageStream As New MemoryStream\r\nch.SaveImage(imageStream)\r\ncontext.Response.BinaryWrite(imageStream.GetBuffer)\r\n\r\nEnd Sub\r\n\r\nReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable\r\nGet\r\nReturn False\r\nEnd Get\r\nEnd Property\r\n\r\nEnd Class\r\n\r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>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 &#8216;httphandler way&#8217; of rendering the chart controls &#8211; [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34,1],"tags":[25,26],"_links":{"self":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts\/34"}],"collection":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":5,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts\/34\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}