Charts in .NET
-
Hello, I need to generate a few charts based on data stored in my database on SQL Server. I had no idea of how to generate charts with standard values itself.A little search on the Internet gave me the following code which works well: Dim Image As New Bitmap(500, 300, PixelFormat.Format32bppRgb) Dim g As Graphics = Graphics.FromImage(Image) Dim redPen As New Pen(Color.Red, 10) Dim blueBrush As New SolidBrush(Color.Blue) Dim myImage As Bitmap Dim p() As Integer = {1000000, 600000, 2500000, 80000} Dim towns() As String = {"A", "B", "C", "D"} Dim myBrushes(4) As Brush myImage = New Bitmap(500, 300, PixelFormat.Format32bppRgb) g = Graphics.FromImage(myImage) ' Create the brushes for drawing myBrushes(0) = New SolidBrush(Color.Red) myBrushes(1) = New SolidBrush(Color.Blue) myBrushes(2) = New SolidBrush(Color.Yellow) myBrushes(3) = New SolidBrush(Color.Green) ' Variables declaration Dim i As Integer Dim xInterval As Integer = 100 Dim width As Integer = 90 Dim height As Integer Dim blackBrush As New SolidBrush(Color.Black) For i = 0 To p.Length - 1 height = (p(i) \ 10000) ' divide by 10000 to adjust barchart to height of Bitmap ' Draws the bar chart using specific colours g.FillRectangle(myBrushes(i), xInterval * i + 50, 280 - height, width, height) ' label the barcharts g.DrawString(towns(i), New Font("Verdana", 12, FontStyle.Bold), Brushes.Black, xInterval * i + 50 + (width / 3), 280 - height - 25) ' Draw the scale g.DrawString(height, New Font("Verdana", 8, FontStyle.Bold), Brushes.Black, 0, 280 - height) ' Draw the axes g.DrawLine(Pens.Brown, 40, 10, 40, 290) ' y-axis g.DrawLine(Pens.Brown, 20, 280, 490, 280) ' x-axis Next myImage.Save(Response.OutputStream, _ System.Drawing.Imaging.ImageFormat.Jpeg) But now i need to know how in the p() array I can input values from the database dynamically i.e the number of values in the database could vary with time.The code should automatically input all the values in the table in the databse and generate the appropriate chart.How do i do this?