I am planning to create a page in a web application that displays a customised chart. The data values for this chart will be drawn from a database. On the page, there will be a control such as a dropdownlist that controls which entries from the database are displayed in the chart.
The step I am struggling with is putting the dropdownlist and the outputted chart on the same page, so that the user can see the chart changing in response to the dropdownlist change.
To create the chart, I am using some code along the following logic:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyBitmap As New Bitmap(100, 100)
Dim Chart As Graphics = Graphics.FromImage(MyBitmap)
Chart.DrawLine(Pens.Yellow, 0, 0, 100, 100)
Chart.DrawLine(Pens.Red, 100, 0, 0, 100)
'The chart drawing parameters are set by variables which take values from a database’
What I am not sure about is how to send the chart image to the page, so that it only forms part of the page. Looking around the web for examples, I have mostly found suggestions were the chart generation is placed in a separate “chart generator page”, which does nothing but create the chart image. In the main/target page, an <img> tag is then placed, with the image source being the chart generating page. Something like this:
<img src="ChartGeneratingPage.aspx" alt="xyz" />
However, I can’t get this to work for my scenario, as I’m not sure how to pass the selected value from the dropdownlist across to code in the separate page that creates the image. I do, however, also suspect that there is a simpler/cleverer way of achieving what I am looking for. For example, would it be possible to have the chart generation code in the target page –that is, the page where the chart is actually displayed, and where we have the dropdownlist control?
Any help would be much appreciated!
PS: I am aware of the new "Chart Controls" that are available for ASP.NET 3.5. However, the charts I need to generate are highly customised, so I don't think I will be able to do this with the Chart Controls.