I want to create a LinearGauge collection based on a result set from a stored procedure. I will not know how many records will be returned until runtime, therefore, I cannot explicitly create instances of new linear gauges. I tried creating an ILIST of the type LinearGauge using the following statement but that was not allowed.
IList<LinearGauge> myGauges = new IList<LinearGauge>();
Can you suggest a way to create the gauge collection as I am looping through a result set? Thanks in advance for your help!
sounds like you have the right idea, but IList is an interface and you can't create an instance of an interface. try new List<LinearGauge>();
Thanks to you, I'm getting closer. However, still not quite there. My code is displaying the correct number of gauges based on the data, and the placement of the gauges in the collection is also working well. The only problem is that only one gauge image is being created, and that same image is being displayed for each gauge. In other words, there are the correct number of gauges being displayed, but they are all the same. I seems like the last gauge in the collection is being used for all of the gauges. Hope that makes sense. Below is my code. Thanks again!
//Instantiate the following classes:
Infragistics.WebUI.UltraWebGauge.UltraGauge ultraGauge1 =
new Infragistics.WebUI.UltraWebGauge.UltraGauge();
LinearGauge myLinearGauge0 = new LinearGauge();
LinearGauge myLinearGauge1 = new LinearGauge();
LinearGauge myLinearGauge2 = new LinearGauge();
LinearGauge myLinearGauge3 = new LinearGauge();
LinearGauge myLinearGauge4 = new LinearGauge();
LinearGauge myLinearGauge5 = new LinearGauge();
LinearGauge myLinearGauge6 = new LinearGauge();
LinearGauge myLinearGauge7 = new LinearGauge();
LinearGauge myLinearGauge8 = new LinearGauge();
LinearGauge myLinearGauge9 = new LinearGauge();
LinearGauge myLinearGauge10 = new LinearGauge();
LinearGauge myLinearGauge11 = new LinearGauge();
LinearGauge myLinearGauge12 = new LinearGauge();
LinearGauge myLinearGauge13= new LinearGauge();
LinearGauge myLinearGauge14 = new LinearGauge();
List<LinearGauge> myGauges = new List<LinearGauge>();
myGauges.Add(myLinearGauge0);
myGauges.Add(myLinearGauge1);
myGauges.Add(myLinearGauge2);
myGauges.Add(myLinearGauge3);
myGauges.Add(myLinearGauge4);
myGauges.Add(myLinearGauge5);
myGauges.Add(myLinearGauge6);
myGauges.Add(myLinearGauge7);
myGauges.Add(myLinearGauge8);
myGauges.Add(myLinearGauge9);
myGauges.Add(myLinearGauge10);
myGauges.Add(myLinearGauge11);
myGauges.Add(myLinearGauge12);
myGauges.Add(myLinearGauge13);
myGauges.Add(myLinearGauge14);
LinearGaugeScale myScale = new LinearGaugeScale();
NumericAxis numericAxis1 = new NumericAxis();
LinearGaugeBarMarker barMarker = new LinearGaugeBarMarker();
LinearGaugeNeedle needleMarker = new LinearGaugeNeedle();
SolidFillBrushElement transparentBrushElement = new SolidFillBrushElement();
SolidFillBrushElement blackBrushElement = new SolidFillBrushElement();
SolidFillBrushElement grayBrushElement = new SolidFillBrushElement();
SolidFillBrushElement greenBrushElement = new SolidFillBrushElement();
SolidFillBrushElement steelblueBrushElement = new SolidFillBrushElement();
SolidFillBrushElement redBrushElement = new SolidFillBrushElement();
SimpleGradientBrushElement mySimpleGradientBrushElement = new SimpleGradientBrushElement();
BoxAnnotation myAnnotation1 = new BoxAnnotation();
BoxAnnotation myAnnotation2 = new BoxAnnotation();
transparentBrushElement.Color = System.Drawing.Color.Transparent;
blackBrushElement.Color = System.Drawing.Color.Black;
grayBrushElement.Color = System.Drawing.Color.Gray;
greenBrushElement.Color = System.Drawing.Color.Green;
redBrushElement.Color = System.Drawing.Color.Red;
steelblueBrushElement.Color = System.Drawing.Color.SteelBlue;
mySimpleGradientBrushElement.StartColor = System.Drawing.Color.LightSteelBlue;
mySimpleGradientBrushElement.EndColor = System.Drawing.Color.White;
mySimpleGradientBrushElement.GradientStyle = Infragistics.UltraGauge.Resources.Gradient.BackwardDiagonal;
//Set the background color
//myLinearGauge.BrushElement = transparentBrushElement;
//Set the corner extent and orientation of Linear gauge
//myLinearGauge.CornerExtent = 50;
//myLinearGauge.Orientation = LinearOrientation.Horizontal;
// Set the gauge annotation
//myAnnotation1.Bounds = new System.Drawing.Rectangle(30, 5, 0, 0);
//myAnnotation1.Label.FormatString = zone;
//myAnnotation1.Label.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold);
//myAnnotation1.Label.BrushElement = steelblueBrushElement;
//myAnnotation2.Bounds = new System.Drawing.Rectangle(175, 5, 0, 0);
//myAnnotation2.Label.FormatString = string.Format("{0:0%}", barValue) + " Compliance";
//myAnnotation2.Label.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold);
//myAnnotation2.Label.BrushElement = steelblueBrushElement;
//ultraGauge1.Annotations.Add(myAnnotation1);
//ultraGauge1.Annotations.Add(myAnnotation2);
//Set the end value of the axis to 1
numericAxis1.EndValue = 1;
numericAxis1.TickmarkInterval = 0.1;
myScale.Axes.Add(numericAxis1);
//Set the following Scale properties:
myScale.EndExtent = 95;
myScale.InnerExtent = 24;
myScale.StartExtent = 5;
myScale.OuterExtent = 36;
//Set the following Labels properties:
myScale.Labels.BrushElement = blackBrushElement;
myScale.Labels.Extent = 11;
myScale.Labels.Font =
new System.Drawing.Font("Arial", 8F,
System.Drawing.FontStyle.Regular);
myScale.Labels.Frequency = 1;
myScale.Labels.FormatString = "<DATA_VALUE:>";
//Set the following major Tickmark properties:
myScale.MajorTickmarks.BrushElement = grayBrushElement;
myScale.MajorTickmarks.EndExtent = 47;
myScale.MajorTickmarks.EndWidth = 2;
myScale.MajorTickmarks.Frequency = 0;
myScale.MajorTickmarks.StartExtent = 26;
myScale.MajorTickmarks.StartWidth = 2;
//Set the following minor Tickmark properties:
myScale.MinorTickmarks.BrushElement = grayBrushElement;
myScale.MinorTickmarks.EndExtent = 30;
myScale.MinorTickmarks.EndWidth = 2;
myScale.MinorTickmarks.Frequency = .2;
myScale.MinorTickmarks.StartExtent = 42;
myScale.MinorTickmarks.StartWidth = 2;
//Set the following Marker properties:
barMarker.InnerExtent = 50;
barMarker.OuterExtent = 140;
//myMarker.SegmentSpan = 1;
//myMarker.StartExtent = 0;
//barMarker.Value = barValue;
barMarker.Precision = 0;
needleMarker.StartExtent = 86;
needleMarker.MidExtent = 86;
needleMarker.EndExtent = 52;
needleMarker.StartWidth = 5;
needleMarker.MidWidth = 17;
needleMarker.EndWidth = 0;
//needleMarker.Value = needleValue;
needleMarker.Precision = 0;
needleMarker.BrushElement = greenBrushElement;
//this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "gaugeDblClick", "<script type='text/javascript'>function clicked() {alert('hello'); }</script>");
//Single x = new Single;
DataTable tbldata = new DataTable();
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["MCISSQLConnection"].ConnectionString;
SqlConnection sTransConn = new SqlConnection(strConn);
SqlCommand sTransCmd = new SqlCommand();
sTransCmd.Connection = sTransConn;
sTransConn.Open();
sTransCmd.CommandText = "MCIS_PortalPart_Compliance '" + "stanislaus" + "', " + "0";
SqlDataReader objTransReader = sTransCmd.ExecuteReader();
Response.Write("<table cellpadding=0 cellspacing=0 class=style1>");
gaugeCounter = 0;
while (objTransReader.Read())
{
//tbldata.Rows.Add(new object[] { objTransReader["Zone"].ToString(), objTransReader["subZone"].ToString(), objTransReader["pctCompliance"], objTransReader["CompStd_1"] });
gaugePosition = Convert.ToInt16((gaugeCounter / Convert.ToSingle(objTransReader["rows"]))* 100) ;
gaugePercent = Convert.ToInt16((1 / Convert.ToSingle(objTransReader["rows"])) * 100);
Response.Write("<tr><td>");
Response.Write(gaugeCounter);
Response.Write(Convert.ToSingle(objTransReader["pctCompliance"]));
Response.Write("</td></tr>");
myGauges[gaugeCounter].BrushElement = mySimpleGradientBrushElement;
needleMarker.Value = Convert.ToSingle(objTransReader["CompStd_1"]);
myScale.Markers.Add(needleMarker);
barMarker.Value = Convert.ToSingle(objTransReader["pctCompliance"]);
if (Convert.ToSingle(barMarker.Value) < .9)
barMarker.BrushElement = redBrushElement;
}
else
barMarker.BrushElement = greenBrushElement;
myScale.Markers.Add(barMarker);
myGauges[gaugeCounter].Scales.Add(myScale);
myGauges[gaugeCounter].Bounds = new System.Drawing.Rectangle(0, gaugePosition, 100, gaugePercent);
myGauges[gaugeCounter].BoundsMeasure = Measure.Percent;
ultraGauge1.Gauges.Add(myGauges[gaugeCounter]);
gaugeCounter += 1;
Response.Write("</table>");
// close all SQL objects.
sTransConn.Close();
sTransConn.Dispose();
sTransCmd.Dispose();
objTransReader.Close();
objTransReader.Dispose();
//ultraGauge1.ClientSideEvents.Click = "UltraGauge1_Click";
ultraGauge1.DeploymentScenario.Mode = ImageDeploymentMode.Session;
//ultraGauge1.DeploymentScenario.FilePath = "GaugeImages";
ultraGauge1.ID = "ultraGuage1";
ultraGauge1.Height = Unit.Pixel(gaugeCounter * 50);
ultraGauge1.Width = Unit.Pixel(400);
ultraGauge1.TabIndex = 0;
this.Controls.Add(ultraGauge1);
//this.FindControl("form1").Controls.Add(ultraGauge1);
don't worry about the ImageUrl for now. just set the ID to something unique for every iteration of that loop.
Thanks for the quick reply, but still no luck. Below is a portion of my code so you can see where I am assigning the value for the ID.
//gaugePosition = Convert.ToInt16((gaugeCounter / Convert.ToSingle(objTransReader["rows"])) * 100);
Response.Write(" - ");
Response.Write(gaugePosition);
Response.Write(gaugePercent);
ultraGauge1.ID = string.Concat("ultraGauge", gaugeCounter.ToString());
gaugePosition += gaugePercent;
//ultraGauge1.ID = "ultraGuage1";
One thing that I am doing is creating only one instance of the markers, Numeric Axis, and scale. Each loop, I am only changing the marker values, then adding the marker to the same scale object, and the same scale object to the new gauge item in the collection. Could reusing the same marker, Axis and scale object for each gauge in the collection be causing the same image to be used for each gauge?
it wouldn't be the same image, but all the images would look identical.
every time you call this code,
you're updating the value of the only needle used by any of the gauges, so only the last value you set will be reflected on any gauge.
i recommend using separate markers, scales, etc in each gauge.
Success!!!!! Thank you so much for your help and patience with me.