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>