problem to create web control using graphics

R

rushikesh.joshi

Hi All,

I want some charting functionality in my ASP.NET application.

I want to show a multiple bar on my web page. It's based on down time
of different servers.
like
server1: down betn 4 AM to 5 AM and 6 PM to 7 PM
server2: down betn 7 AM to 7:30 AM
server3: down betn 3 AM to 5 AM and 2 Pm to 3 PM
and so on....

Now, all total number of server is in database and i want to display
server down chart in just besides of this server on my summary page.

Now problem is, this page is dynamic and my chart for server may
contain differnt color and different segments.

So for that, I want to create a custom control/User control so i can
avoid the repeatative programing.

Now i want to use graphics for this in my control. and it's working
fine for asigning that aspx page from my image src="" attribute.

but this is stateless, and i can only pass different parameter in
querysting like...
img1.ImageUrl = "BarChart.aspx?startTime=" + t1 + "&endTime=" + t2;

but instead of query string i want to store it in either session or
viewState to use it in my BarChart.aspx page. But it's not working. any
idea what would be the problem.

Below is my code, i have two file one is BarChart.aspx and
Server_down_testing.aspx.
I m only uploading the codebehind.

See the below code is working fine, but this is not robust and every
time i have to pass starttime and endtime in query string, instead of
that i want to pass this as array in the session or viewstate.

i tried it by simply session/viewstate but every time it's not
generating the new image, it's taking the first one...

also if we can create user control/custom control then it's good for
me.

Thanks & Regards
Rushikesh



///////////////***** BarChart.aspx *******************//////////////

<%@ Page Language="C#" debug="true"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>

<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e)
{
Single width, height;
width = 800;
height = 30;
int maxSegment = 24;

string color;
int start, end;

Bitmap objBitmap = new Bitmap(width, height);

Graphics objGraphic = Graphics.FromImage(objBitmap);

start = Convert.ToSingle(Request["startTime"]);
end = Convert.ToSingle(Request["endTime"]);
SolidBrush colorBrush = new SolidBrush(Color.Red);

Pen blackPen = new Pen(Color.Black, 2);

objGraphic.FillRectangle(whiteBrush, 0, 0, width, height);

Single newPos, newWidth;
newPos = (width / maxSegment) * start;
newWidth = (width / maxSegment) * (start - end);

objGraphic.FillRectangle(colorBrush, newPos, 0, newWidth,
height);
Response.Write(newPos.ToString() + " : " +
newWidth.ToString());
Response.ContentType = "image/gif";

objBitmap.Save(Response.OutputStream, ImageFormat.Gif);

}

</script>



///**************** Server_down_testing.aspx
**********************/////

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="calendarTest.aspx.cs" Inherits="calendarTest" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>


<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e)
{
for (int i = 1; i <= 10; )
{
System.Web.UI.WebControls.Image img1 = new
System.Web.UI.WebControls.Image();
img1.ID = "img-" + i;

v1= 2 * i;
v2= 4 * i;
v3= 5 * i;
// Session["v1"] = v1;
// Session["v2"] = v2;
// Session["v3"] = v3;

//img1.ImageUrl = "BarChart_CSharp1.aspx";
img1.ImageUrl = "BarChart.aspx?startTime=" + v1 + "&endTime=" +
v2;
Panel1.Controls.Add(img1);
i += 1;
}

}

</script>



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:panel ID="Panel1" runat="server" Height="50px"
Width="622px">

</asp:panel>
</div>
</form>
</body>
</html>


Thanks & Regards,
Rushikesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top