Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...insert a chart in webforminsert a chart in webform
Previous
 
Next
New Post
4/8/2008 3:18 AM
 

Hi, Im new to ASP.NET and i need to include a chart in my webform. That chart should read data from sql database for its X and Y axis's data. I tried using dotnetcharting, but I cant really get it installed, When I use Webchart tool it doesnt support any chart types when  i finished installing it, When i use ComponentArt charting tool,Im able to do the database linking but I received an error when I try to view in browser, It says login failed for ASPNET user, where this user is the ASP.NET machine account for ASP.NET application. So I used the following example to generate a chart, but it is not linked to any database. So can anyone help me on how to modify this codes so that it grabs data from my database?

My server name is sphang, database= T2000, Table= Monthly, X-axis Column= Week1,week2,week3,week4, Y-axis column= Percentage.....

The code as follows......................

 'Declare your object variables

        Dim i As Integer

        'Build a BitMap that will act as the pallet and container

        'for the bar graph. Here 600 is the width and 300 is the height. 

        'These values could also be passed as parameters.

        Dim objBitMap As New Bitmap(400, 200)

 

        'Declare your Graphics objects for painting graphics on you newly created bitmap.

        Dim objGraphics As Graphics

        objGraphics = Graphics.FromImage(objBitMap)

        'Set the background color to silver

        objGraphics.Clear(Color.Silver)

 

        'Build an array of values for the bar and pie chart. 

        'These values could also be pulled from a database.

        Dim arrValues(4) As Integer

        arrValues(0) = 100

        arrValues(1) = 135

        arrValues(2) = 115

        arrValues(3) = 125

        arrValues(4) = 75

 

        Dim arrValueNames(4) As String

        arrValueNames(0) = "Jan"

        arrValueNames(1) = "Feb"

        arrValueNames(2) = "Mar"

        arrValueNames(3) = "Apr"

        arrValueNames(4) = "May"

 

        'Write out a title for your bar and pie chart.

        objGraphics.DrawString("5 Month Projection Report", New Font("Tahoma", 16), Brushes.Black, New PointF(5, 5))

 

        'Create a legend to describe your bar and chart.

        Dim symbolLeg As PointF = New PointF(335, 20)

        Dim descLeg As PointF = New PointF(360, 16)

 

        For i = 0 To arrValueNames.Length - 1

            objGraphics.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10)

            objGraphics.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10)

 

            objGraphics.DrawString(arrValueNames(i).ToString, New Font("Tahoma", 10), Brushes.Black, descLeg)

            symbolLeg.Y += 15

            descLeg.Y += 15

        Next i

 

        'Loop through the values to create the Bar Chart.

        For i = 0 To arrValues.Length - 1

            objGraphics.FillRectangle(New SolidBrush(GetColor(i)), (i * 35) + 15, 200 - arrValues(i), 20, arrValues(i) + 5)

            objGraphics.DrawRectangle(Pens.Black, (i * 35) + 15, 200 - arrValues(i), 20, arrValues(i) + 5)

        Next

 

        'Loop through the values to create the Pie Chart.

        Dim sglCurrentAngle As Single = 0

        Dim sglTotalAngle As Single = 0

        i = 0

 

        For i = 0 To arrValues.Length - 1

            'Current Value / (sum of all the Values) * 360 degree angle

            sglCurrentAngle = arrValues(i) / 550 * 360

 

            objGraphics.FillPie(New SolidBrush(GetColor(i)), 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle)

            objGraphics.DrawPie(Pens.Black, 220, 95, 100, 100, sglTotalAngle, sglCurrentAngle)

 

            sglTotalAngle += sglCurrentAngle

        Next i

 

        objBitMap.Save(Response.OutputStream, ImageFormat.Gif)

    End Sub
    'This function returns a color for the bar and pie charts.

    Private Function GetColor(ByVal itemIndex As Integer) As Color

        Dim objColor As Color

 

        Select Case itemIndex

            Case 0

                objColor = Color.Blue

            Case 1

                objColor = Color.Red

            Case 2

                objColor = Color.Yellow

            Case 3

                objColor = Color.Purple

            Case 4

                objColor = Color.Orange

            Case 5

                objColor = Color.Brown

            Case 6

                objColor = Color.Gray

            Case 7

                objColor = Color.Maroon

            Case Else

                objColor = Color.Green

        End Select

 

        Return objColor

 

    End Function


End Class

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...insert a chart in webforminsert a chart in webform


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out