Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Grafico a Barre - << VERSIONE C# >>


Realizzare un grafico a barre


<%@ Page Language="vb" AutoEventWireup="false"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="vbscript" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim i As Integer
  Dim bm As New Bitmap(400, 200)
  Dim g As Graphics
  g = Graphics.FromImage(bm)
  g.Clear(Color.Snow)
  g.DrawString("Grafico a barre", New Font("Verdana", 14), Brushes.Black, New PointF(5, 5))

  Dim yaxis(7) As Integer
  yaxis(0) = 12
  yaxis(1) = 7
  yaxis(2) = 4
  yaxis(3) = 10
  yaxis(4) = 3
  yaxis(5) = 11
  yaxis(6) = 5

  Dim xaxis(7) As String
  xaxis(0) = "Uno"
  xaxis(1) = "Due"
  xaxis(2) = "Tre"
  xaxis(3) = "Quattro"
  xaxis(4) = "Cinque"
  xaxis(5) = "Sei"
  xaxis(6) = "Sette"

  Dim symbolLeg As PointF = New PointF(300, 20)
  Dim descLeg As PointF = New PointF(320, 16)
  For i = 0 To xaxis.Length - 1
    g.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10)
    g.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10)
    g.DrawString(xaxis(i).ToString, New Font("Arial", 10), Brushes.Black, descLeg)
    symbolLeg.Y += 15
    descLeg.Y += 15
  Next i
  Dim spacebetbars As Integer = 35
  Dim scale As Integer = 10
  For i = 0 To yaxis.Length - 1
    g.FillRectangle(New SolidBrush(GetColor(i)), (i * spacebetbars) + 15, 200 - (yaxis(i) * scale), 20, (yaxis(i) * scale) + 5)
    g.DrawRectangle(Pens.Black, (i * spacebetbars) + 15, 200 - (yaxis(i) * scale), 20, (yaxis(i) * scale) + 5)
  Next
  Dim p As New Pen(Color.Black, 2)
  g.DrawRectangle(p, 1, 1, 398, 198)
  bm.Save(Response.OutputStream, ImageFormat.Jpeg)
End Sub

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.Peru
    Case 4
      objColor = Color.Orange
    Case 5
      objColor = Color.Coral
    Case 6
      objColor = Color.Gray
    Case 7
      objColor = Color.Maroon
    Case Else
      objColor = Color.Green
  End Select
  Return objColor
End Function
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>



Scarica il Codice...


Stampa la pagina


 








Inizio pagina

risorse per webmaster