Hi,
What i am trying to do is draw a line graph by reading data from a sql server database. while it appears to be doing this correctly the image doesnt appear once the code has finished executing. I have set a image url to equal the location of the image but with no result. it does however work if i was to reference an image (eg picture) from my own documents but not the graph recreated.
Any insight in to this problem would be great.
Code is here if it helps
protected void Page_Load(object sender, EventArgs e)
{
objConnection = new SqlConnection("Data Source=FERGAL\\SQLEXPRESS;Initial Catalog=BlarneyGolfResort;Integrated Security=True;");
objGraphScoresDA = new SqlDataAdapter("Select * from tblScore where MemberID ='" + Session["MemberID"] + "'", objConnection);
objGraphScoresCB = new SqlCommandBuilder(objGraphScoresDA);
Retrieve();
FindMaxValue();
CreateBitMap();
InitaliseGraphics();
Draw();
}
public void Retrieve()
{
objDataSet.Clear();
objGraphScoresDA.FillSchema(objDataSet, SchemaType.Source, "tblScore");
objGraphScoresDA.Fill(objDataSet, "tblScore");
}
public void FindMaxValue()
{
int myInt = 0;
objDataTable = objDataSet.Tables["tblScore"];
foreach (DataRow drowRow in objDataTable.Rows)
{
myInt = Int32.Parse(drowRow["Total"].ToString());
if (myInt > MaxValue)
{
MaxValue = myInt;
}
}
XScale = ImageWidth / (objDataTable.Rows.Count - 1);
YScale = ImageHeight / MaxValue;
}
//create bitmap
protected void CreateBitMap()
{
objBitmap = new Bitmap(ImageWidth, ImageHeight);
}
//initalise the graphics class
protected void InitaliseGraphics()
{
objGraphics = Graphics.FromImage(objBitmap);
}
protected void Draw()
{
for (int intRowCounter = 0; intRowCounter <= objDataTable.Rows.Count - 1; intRowCounter++)
{
DataRow drowRow = objDataTable.Rows[intRowCounter];
objGraphics.DrawLine(Pens.Red, PrevX, PrevY, intRowCounter * XScale, ImageHeight - (float.Parse(drowRow.ItemArray.GetValue(43).ToString()) * float.Parse(YScale.ToString())));
PrevX = intRowCounter * XScale;
PrevY = ImageHeight - (Int32.Parse(drowRow.ItemArray.GetValue(43).ToString()) * Int32.Parse(YScale.ToString()));
}
objBitmap.Save("C:\\img1.gif");
//System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
// img.Height = 100;
//img.Width = 100;
Image4.ImageUrl = "C:\\img1.gif";
//img.BackColor = System.Drawing.Color.Aquamarine;
//Panel1.Controls.Add(img);
//objBitmap.Save(Response.OutputStream, ImageFormat.Bmp);
}
What i am trying to do is draw a line graph by reading data from a sql server database. while it appears to be doing this correctly the image doesnt appear once the code has finished executing. I have set a image url to equal the location of the image but with no result. it does however work if i was to reference an image (eg picture) from my own documents but not the graph recreated.
Any insight in to this problem would be great.
Code is here if it helps
protected void Page_Load(object sender, EventArgs e)
{
objConnection = new SqlConnection("Data Source=FERGAL\\SQLEXPRESS;Initial Catalog=BlarneyGolfResort;Integrated Security=True;");
objGraphScoresDA = new SqlDataAdapter("Select * from tblScore where MemberID ='" + Session["MemberID"] + "'", objConnection);
objGraphScoresCB = new SqlCommandBuilder(objGraphScoresDA);
Retrieve();
FindMaxValue();
CreateBitMap();
InitaliseGraphics();
Draw();
}
public void Retrieve()
{
objDataSet.Clear();
objGraphScoresDA.FillSchema(objDataSet, SchemaType.Source, "tblScore");
objGraphScoresDA.Fill(objDataSet, "tblScore");
}
public void FindMaxValue()
{
int myInt = 0;
objDataTable = objDataSet.Tables["tblScore"];
foreach (DataRow drowRow in objDataTable.Rows)
{
myInt = Int32.Parse(drowRow["Total"].ToString());
if (myInt > MaxValue)
{
MaxValue = myInt;
}
}
XScale = ImageWidth / (objDataTable.Rows.Count - 1);
YScale = ImageHeight / MaxValue;
}
//create bitmap
protected void CreateBitMap()
{
objBitmap = new Bitmap(ImageWidth, ImageHeight);
}
//initalise the graphics class
protected void InitaliseGraphics()
{
objGraphics = Graphics.FromImage(objBitmap);
}
protected void Draw()
{
for (int intRowCounter = 0; intRowCounter <= objDataTable.Rows.Count - 1; intRowCounter++)
{
DataRow drowRow = objDataTable.Rows[intRowCounter];
objGraphics.DrawLine(Pens.Red, PrevX, PrevY, intRowCounter * XScale, ImageHeight - (float.Parse(drowRow.ItemArray.GetValue(43).ToString()) * float.Parse(YScale.ToString())));
PrevX = intRowCounter * XScale;
PrevY = ImageHeight - (Int32.Parse(drowRow.ItemArray.GetValue(43).ToString()) * Int32.Parse(YScale.ToString()));
}
objBitmap.Save("C:\\img1.gif");
//System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
// img.Height = 100;
//img.Width = 100;
Image4.ImageUrl = "C:\\img1.gif";
//img.BackColor = System.Drawing.Color.Aquamarine;
//Panel1.Controls.Add(img);
//objBitmap.Save(Response.OutputStream, ImageFormat.Bmp);
}