Creating Thermometer Chart in C#

6/11/2009

Have you ever had someone calling you up and saying to you that they needed a chart that looked like a thermometer today and they didn't want it to be simply an image that they update? No? Well I did the other day. So I quickly slapped together a handler to create the chart for me. Note that this isn't a nicely created piece of code but hey, I thought someone might get something out of it:

The code above is a handler that takes in a Percent (percent of the graph to show as red), Max (maximum value), and Dollars value (Whether this is a number or dollar amount). But in return it creates a decent looking graph. I mean it isn't perfect, but it works... Anyway, try it out, leave feedback, and happy coding.

Comments

AndreasOctober 19, 2010 4:26 AMthx, that's the goalJames CraigOctober 18, 2010 12:52 PMI created it as an http handler (you'd add it to your web.config under httphandlers). Since you're most likely calling it like AQEEL (which you shouldn't, but I missed his comments or I would have responded), you're running into the issue. The handler uses the Response property to fill what is sent from the page (you'll notice that your response is just the image and no html). If you set it up as an http handler and call it like this from your default.aspx:<img src="Thermometer.ashx?Percent=50*Max=100&Dollars=1" />It should run. Now you could also take out the actual thermometer generation code and just use that in its own class (generate the jpg on the fly, or daily, or whatever). That's another option.AndreasOctober 18, 2010 10:18 AMhi, great control, but i got a problem. i've got a default.aspx with a menu and a table where the image with the process request is in. but when i run the solution only the the thermometer is displayed and the menu and other controls get lost ?please helpthxAQEELNovember 25, 2009 7:05 PMuse like thisin Default.aspx on load event type following Thermometer tm = new Thermometer();tm.ProcessRequest(HttpContext.Current);and call default.aspx?Percent=50&Max=100&Dollars=5000AQEELNovember 25, 2009 6:12 PMHi There, just want to say awesome, at least i can know how to work with graphics, just one question how do i call it?