Vai all'ultimo messaggio della discussione Vai all'ultimo messaggio  

3 pagine: [1] 2 3 Avanti >>


creazione istogramma con records
corsaronero
corsaronero non è online. Ultima attività: 14/04/2009 20.38.57corsaronero
il 23 settembre 2008 alle 14.19
72 messaggi dal 31 maggio 2008
Salve a tutti Volevo sapere se qualcuno sa come fare in visual studio 2008 o 2005
o in c# un istogramma una volta contati i records
Grazie
Microsoft Most Valuable Professional
Re: creazione istogramma con records
SM15455
SM15455 non è online. Ultima attività: 02/07/2009 15.17.16SM15455 Top Poster
il 23 settembre 2008 alle 15.19
Contributi | Blog | 2.787 messaggi dal 06 settembre 2002
Ciao,

ti consiglio questo articolo, è per asp.net 1.1, ma valido anche per le versioni successive.

http://www.aspitalia.com/articoli/asp.net/grafici.aspx

HTH

Nothing can be born from hartred

Stefano (SM15455) Mostarda
http://blogs.aspitalia.com/SM15455
Rome Italy
Re: creazione istogramma con records
corsaronero
corsaronero non è online. Ultima attività: 14/04/2009 20.38.57corsaronero
il 26 settembre 2008 alle 12.59
72 messaggi dal 31 maggio 2008
Stefano grazie per l info, sono riuscito a creare l'istogramma ma ho un aproblema se cerco di crearlo all interno di una ContentPlaceHolderID non mi visualizza ne la masterpage ne la regione ma viene visualizzato solo l'istogramma:
Codice Grafico:


public partial class amministratore_Istogramma3D : System.Web.UI.Page
{

class Rect
{
public Rect(Color rectColor, RectangleF rectF, double amount)
{
_rectColor = rectColor;
_rectF = rectF;
_amount = amount;
}
private Color _rectColor;
private RectangleF _rectF;
private double _amount;

public Color RectColor
{
get { return _rectColor; }
}

public RectangleF RectF
{
get { return _rectF; }
}

public double Amount
{
get { return _amount; }
}
}

class RectCollection : CollectionBase
{
public int Add(Rect rect)
{
return List.Add(rect);
}
public Rect this[int i]
{
get { return (Rect)List[i]; }
}
}

protected void Grafico()
{
int bmpHeight = 350;
int bmpWidth = 350;
int graphHeight = 300,
maxRepresentedValue = 500000,
itemWidth = 50,
itemDistance = 10,
borderDistance = 30,
rowInterval = 50000,
GraphDepth = 15;
int graphWidth = 300;

Font font = new Font("arial", 8); //Font utilizzato per le scritte
RectCollection rc = new RectCollection();
//istanzia gli oggetti grafici

using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Request.PhysicalApplicationPath + "db.mdb;Persist Security Info=False"))
{
conn.Open();
OleDbCommand cm = new OleDbCommand("SELECT COUNT(*) FROM torta", conn);
int numElementi = Convert.ToInt32(cm.ExecuteScalar());
itemWidth = (graphWidth - ((itemDistance + GraphDepth) * (numElementi + 1))) / numElementi;
cm.CommandText = "SELECT descrizione, qta, colore FROM torta";
OleDbDataReader rd = cm.ExecuteReader();
int x = borderDistance;
while (rd.Read())
{
x += itemDistance;
float rectHeight = (float)((Convert.ToDouble(rd["QTA"]) * graphHeight) / maxRepresentedValue);
rc.Add(new Rect(ColorTranslator.FromHtml(Convert.ToString(rd["COLORE"])), new RectangleF(x, graphHeight - rectHeight + borderDistance + GraphDepth, itemWidth, rectHeight), Convert.ToDouble(rd["QTA"])));
x += itemWidth + GraphDepth;
}
}

Bitmap bitmap = new Bitmap(bmpWidth, bmpHeight);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.SmoothingMode = SmoothingMode.None;

//Disegna un rettangolo delle dimensioni dell'immagine riempendo lo sfondo col bianco
graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, bmpWidth, bmpHeight);

graphics.FillPolygon(new SolidBrush(Color.LightSlateGray), new PointF[] { new PointF(borderDistance - GraphDepth + 1, borderDistance + GraphDepth), new PointF(borderDistance, borderDistance), new PointF(borderDistance, borderDistance + graphHeight), new PointF(borderDistance - GraphDepth, borderDistance + graphHeight + GraphDepth) });
graphics.FillPolygon(new SolidBrush(Color.LightSlateGray), new PointF[] { new PointF(borderDistance, borderDistance + graphHeight + 1), new PointF(borderDistance + graphWidth - 2, borderDistance + graphHeight + 1), new PointF(borderDistance + graphWidth - GraphDepth, borderDistance + graphHeight + GraphDepth), new PointF(borderDistance - GraphDepth, borderDistance + graphHeight + GraphDepth) });

for (int i = maxRepresentedValue; i >= 0; i -= rowInterval)
{
float y = (float)((i * graphHeight) / maxRepresentedValue) + borderDistance;
graphics.DrawLine(new Pen(Color.LightGray), borderDistance + 1, y, borderDistance + graphWidth - 1, y);
graphics.DrawLine(new Pen(Color.LightGray), borderDistance, y, borderDistance - GraphDepth, y + GraphDepth);
graphics.DrawString(Convert.ToString((maxRepresentedValue - i) / 10000), font, new SolidBrush(Color.Blue), 1, y - (font.Height / 2) + GraphDepth);
}

graphics.DrawRectangle(new Pen(Color.Black), borderDistance, borderDistance, graphWidth, graphHeight);
graphics.DrawPolygon(new Pen(Color.Black), new PointF[] { new PointF(borderDistance - GraphDepth, borderDistance + GraphDepth), new PointF(borderDistance, borderDistance), new PointF(borderDistance, borderDistance + graphHeight), new PointF(borderDistance - GraphDepth, borderDistance + graphHeight + GraphDepth) });
graphics.DrawPolygon(new Pen(Color.Black), new PointF[] { new PointF(borderDistance, borderDistance + graphHeight), new PointF(borderDistance + graphWidth, borderDistance + graphHeight), new PointF(borderDistance + graphWidth - GraphDepth, borderDistance + graphHeight + GraphDepth), new PointF(borderDistance - GraphDepth, borderDistance + graphHeight + GraphDepth) });

foreach (Rect r in rc)
{
graphics.FillPolygon(new SolidBrush(r.RectColor), new PointF[] { new PointF(r.RectF.Right, r.RectF.Top), new PointF(r.RectF.Right + GraphDepth, r.RectF.Top - GraphDepth), new PointF(r.RectF.Right + GraphDepth, r.RectF.Bottom - GraphDepth), new PointF(r.RectF.Right, r.RectF.Bottom) });
graphics.DrawPolygon(new Pen(Color.Black), new PointF[] { new PointF(r.RectF.Right, r.RectF.Top), new PointF(r.RectF.Right + GraphDepth, r.RectF.Top - GraphDepth), new PointF(r.RectF.Right + GraphDepth, r.RectF.Bottom - GraphDepth), new PointF(r.RectF.Right, r.RectF.Bottom) });
graphics.FillPolygon(new SolidBrush(r.RectColor), new PointF[] { new PointF(r.RectF.Left + GraphDepth, r.RectF.Top - GraphDepth), new PointF(r.RectF.Right + GraphDepth, r.RectF.Top - GraphDepth), new PointF(r.RectF.Right, r.RectF.Top), new PointF(r.RectF.Left, r.RectF.Top) });
graphics.DrawPolygon(new Pen(Color.Black), new PointF[] { new PointF(r.RectF.Left + GraphDepth, r.RectF.Top - GraphDepth), new PointF(r.RectF.Right + GraphDepth, r.RectF.Top - GraphDepth), new PointF(r.RectF.Right, r.RectF.Top), new PointF(r.RectF.Left, r.RectF.Top) });
graphics.FillRectangle(new SolidBrush(r.RectColor), r.RectF);
graphics.DrawRectangle(new Pen(Color.Black), r.RectF.X, r.RectF.Y, r.RectF.Width, r.RectF.Height);
}

//Imposta il Content-Type e ritorna l'immagine allo stream
Response.ContentType = "image/gif";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
bitmap.Dispose();
}
#region Codice generato da Progettazione Web Form
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: questa chiamata è richiesta da Progettazione Web Form ASP.NET.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
}
#endregion

protected void Page_Load(object sender, EventArgs e)
{

}
}



Codice Content Place:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<table style="width: 100%">
<tr>
<td style="width: 388px">

<script type="text/C#" runat="server" >

protected void Page_Load(object sender, EventArgs e)
{
Grafico(); // Ho provato pure a richiamarlo qui ma niente visualizza solo il grafico in un unica pagina....
}

</script>

</td>
<td>

</td>
</tr>




</table>


</asp:Content>
Re: creazione istogramma con records
manuel0081
manuel0081 non è online. Ultima attività: 26/06/2009 14.22.12manuel0081
il 26 settembre 2008 alle 19.47
blogs.ugidotnet.org | 868 messaggi dal 22 febbraio 2006
forse mi è sfuggita la master...
Re: creazione istogramma con records
corsaronero
corsaronero non è online. Ultima attività: 14/04/2009 20.38.57corsaronero
il 27 settembre 2008 alle 11.32
72 messaggi dal 31 maggio 2008
Ecco la Master:


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Administrator.master.cs" Inherits="Administrator" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
width: 200px;
height: 45px;
}
.style2
{
width: 862px;
height: 45px;
}
.style3
{
width: 65px;
}
.style4
{
width: 862px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;
<table border="1" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%; border-left-color: threedlightshadow; border-bottom-color: threedlightshadow; border-top-style: solid; border-top-color: threedlightshadow; border-right-style: solid; border-left-style: solid; border-right-color: threedlightshadow; border-bottom-style: solid;">
<tr>
<td style="border-style: solid; border-color: threedlightshadow; vertical-align: middle; text-align: center; "
class="style1">
<asp:Image ID="Image1" runat="server" ImageUrl="~/amministratore/img_amministratore/Logo_specialeStampa.gif" /></td>
<td style="border-style: solid; border-color: threedlightshadow; vertical-align: middle; text-align: right; "
class="style2">
<table style="vertical-align: middle; text-align: right">
<tr>
<td style="vertical-align: middle; text-align: center" class="style3">
<asp:Image ID="Image5" runat="server" ImageUrl="~/amministratore/img_amministratore/system-lock-screen.png" /></td>
<td style="vertical-align: middle; width: 100px; font-family: Arial; text-align: center">
<asp:Label ID="Label5" runat="server" Text="Logout"></asp:Label></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="vertical-align: text-top; width: 200px; text-align: center; border-left-color: threedlightshadow; border-bottom-color: threedlightshadow; border-top-style: solid; border-top-color: threedlightshadow; border-right-style: solid; border-left-style: solid; border-right-color: threedlightshadow; border-bottom-style: solid;">
<table align="center">
<tr>
<td style="vertical-align: middle; width: 58px; height: 60px; text-align: center">
<asp:Image ID="Image2" runat="server"
ImageUrl="~/amministratore/img_amministratore/dialog-apply.png"
DescriptionUrl="~/amministratore/ManagerProducts.aspx" /></td>
<td style="vertical-align: middle; width: 100px; font-family: Arial; height: 60px;
text-align: center">
<asp:HyperLink ID="HyperLink1" runat="server" ForeColor="Black"
NavigateUrl="~/amministratore/ManagerProducts.aspx">Manager Products</asp:HyperLink>
</td>
</tr>
<tr>
<td style="vertical-align: middle; width: 58px; height: 60px; text-align: center">
<asp:Image ID="Image3" runat="server" ImageUrl="~/amministratore/img_amministratore/dialog-apply.png" /></td>
<td style="vertical-align: middle; width: 100px; font-family: Arial; height: 60px;
text-align: center">
<asp:Label ID="Label2" runat="server" Text="Setting"></asp:Label></td>
</tr>
<tr>
<td style="vertical-align: middle; width: 58px; height: 60px; text-align: center">
<asp:Image ID="Image4" runat="server" ImageUrl="~/amministratore/img_amministratore/dialog-apply.png" /></td>
<td style="vertical-align: middle; width: 100px; font-family: Arial; height: 60px;
text-align: center">
<asp:Label ID="Label3" runat="server" Text="Office Organizer"></asp:Label></td>
</tr>
<tr>
<td style="vertical-align: middle; width: 58px; height: 60px; text-align: center">
<asp:Image ID="Image6" runat="server" ImageUrl="~/amministratore/img_amministratore/dialog-apply.png" /></td>
<td style="vertical-align: middle; width: 100px; font-family: Arial; height: 60px;
text-align: center">
<asp:Label ID="Label4" runat="server" Text="System users"></asp:Label></td>
</tr>
</table>
</td>
<td style="border-style: solid; border-color: threedlightshadow; vertical-align: text-top; text-align: center; "
class="style4">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

</asp:contentplaceholder>
</td>
</tr>
</table>
&nbsp;
</div>
</form>
</body>
</html>
Re: creazione istogramma con records
manuel0081
manuel0081 non è online. Ultima attività: 26/06/2009 14.22.12manuel0081
il 27 settembre 2008 alle 12.06
blogs.ugidotnet.org | 868 messaggi dal 22 febbraio 2006
il problema è che stai cambiando il tipo di response in img... quindi non ti fa vedere il resto.
Re: creazione istogramma con records
corsaronero
corsaronero non è online. Ultima attività: 14/04/2009 20.38.57corsaronero
il 27 settembre 2008 alle 12.10
72 messaggi dal 31 maggio 2008
Quindi mi sapresti dire come dovrei fare Grazie
Re: creazione istogramma con records
Vmark
Vmark non è online. Ultima attività: 24/06/2009 13.13.36Vmark
il 27 settembre 2008 alle 13.59
461 messaggi dal 08 gennaio 2007
Ciao, un metodo veloce, nel content metti una img così:
<asp:Image ID="Image1" runat="server" ImageUrl="~/grafici/grafico.aspx" />


Saluti

3 pagine: [1] 2 3 Avanti >>

Vai a:
Torna al forum |   Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.

COMMUNITY
ULTIMI MESSAGGI
MEDIA
IN EVIDENZA
MISC
Powered by .db Forums "Caesar Reborn" v. 2009.6.9