I have a winform that has two radio buttons. Depending on the button that is checked a certain line chart should display. For various reasons I can not use separate winforms.
The radio button is checked as follows:
private void radioButtons_CheckedChanged(object sender, EventArgs e) { this.ultraChart1.DataSource = GetColumnData(uI, noiseCriteria, newPath, roomCriteria); this.ultraChart1.DataBind(); }
The graphs currently are made as follows:
private DataTable GetColumnData(int[] userInput, int NC, string path, int RC) { if (radioButton1.Checked) { // Make annotation for NC # Infragistics.UltraChart.Resources.Appearance.PaintElement paintElement1 = new Infragistics.UltraChart.Resources.Appearance.PaintElement(); Infragistics.UltraChart.Resources.Appearance.EllipseAnnotation ellipseAnnotation1 = new Infragistics.UltraChart.Resources.Appearance.EllipseAnnotation(); ellipseAnnotation1.Height = -1; ellipseAnnotation1.Location.Column = 6; ellipseAnnotation1.Location.LocationX = 0; ellipseAnnotation1.Location.LocationY = 0; ellipseAnnotation1.Location.Row = 11; ellipseAnnotation1.Location.Type = Infragistics.UltraChart.Shared.Styles.LocationType.RowColumn; ellipseAnnotation1.Location.ValueX = 0; ellipseAnnotation1.Location.ValueY = 0; ellipseAnnotation1.PE = paintElement1; ellipseAnnotation1.TextStyle.HorizontalAlign = System.Drawing.StringAlignment.Center; ellipseAnnotation1.Width = -1; this.ultraChart1.Annotations.Annotations.Add(ellipseAnnotation1); ellipseAnnotation1.Text = "NC: " + NC.ToString();
DataTable mydata = new DataTable(); // Define the columns and their names mydata.Columns.Add("Series Labels", typeof(string)); mydata.Columns.Add("63", typeof(int)); mydata.Columns.Add("125", typeof(int)); mydata.Columns.Add("250", typeof(int)); mydata.Columns.Add("500", typeof(int)); mydata.Columns.Add("1k", typeof(int)); mydata.Columns.Add("2k", typeof(int)); mydata.Columns.Add("4k", typeof(int)); // Add the rows of data mydata.Rows.Add(new Object[] { "NC 65", 80, 75, 71, 68, 66, 64, 63 }); mydata.Rows.Add(new Object[] { "NC 60", 77, 71, 67, 63, 61, 59, 58 }); mydata.Rows.Add(new Object[] { "NC 55", 74, 67, 62, 58, 56, 54, 53 }); mydata.Rows.Add(new Object[] { "NC 50", 71, 64, 58, 54, 51, 49, 48 }); mydata.Rows.Add(new Object[] { "NC 45", 67, 60, 54, 49, 46, 44, 43 }); mydata.Rows.Add(new Object[] { "NC 40", 64, 56, 50, 45, 41, 39, 38 }); mydata.Rows.Add(new Object[] { "NC 35", 60, 52, 45, 40, 36, 34, 33 }); mydata.Rows.Add(new Object[] { "NC 30", 57, 48, 41, 35, 31, 29, 28 }); mydata.Rows.Add(new Object[] { "NC 25", 54, 44, 37, 31, 27, 24, 22 }); mydata.Rows.Add(new Object[] { "NC 20", 51, 40, 33, 26, 22, 19, 17 }); mydata.Rows.Add(new Object[] { "NC 15", 47, 36, 29, 22, 17, 14, 12 }); // Will be dynamic based on read in values mydata.Rows.Add(new Object[] { "User Input", userInput[0], userInput[1], userInput[2], userInput[3], userInput[4], userInput[5], userInput[6] }); /* // Overriding NC lines to be grey for (int i = 0; i < 11; i++) { Override override1 = new Override(); override1.Column = -2; // all columns override1.Row = i; // row i override1.PE = new PaintElement(Color.Gray); this.ultraChart1.Override.Add(override1); } */ // Overriding User Input to be Red Override override1 = new Override(); override1.Column = -2; // all columns override1.Row = 11; // row i override1.PE = new PaintElement(Color.Red); this.ultraChart1.Override.Add(override1);
this.ultraChart1.InvalidateLayers(); ultraChart1.TitleTop.Text = path; return mydata; } else { // Make annotation for RC Speech Interference Level # Infragistics.UltraChart.Resources.Appearance.PaintElement paintElement1 = new Infragistics.UltraChart.Resources.Appearance.PaintElement(); Infragistics.UltraChart.Resources.Appearance.CalloutAnnotation calloutAnnotation1 = new Infragistics.UltraChart.Resources.Appearance.CalloutAnnotation(); calloutAnnotation1.Height = -1; calloutAnnotation1.Location.Column = 4; calloutAnnotation1.Location.LocationX = 0; calloutAnnotation1.Location.LocationY = 0; calloutAnnotation1.Location.Row = 0; calloutAnnotation1.Location.Type = Infragistics.UltraChart.Shared.Styles.LocationType.RowColumn; calloutAnnotation1.Location.ValueX = 0; calloutAnnotation1.Location.ValueY = 0; calloutAnnotation1.PE = paintElement1; calloutAnnotation1.TextStyle.HorizontalAlign = System.Drawing.StringAlignment.Center; calloutAnnotation1.Width = -1; this.ultraChart1.Annotations.Annotations.Add(calloutAnnotation1); calloutAnnotation1.Text = "SIL: " + RC.ToString(); int speechInterferenceLine = RC; DataTable mydata = new DataTable(); // Define the columns and their names mydata.Columns.Add("Series Labels", typeof(string)); mydata.Columns.Add("63", typeof(int)); mydata.Columns.Add("125", typeof(int)); mydata.Columns.Add("250", typeof(int)); mydata.Columns.Add("500", typeof(int)); mydata.Columns.Add("1k", typeof(int)); mydata.Columns.Add("2k", typeof(int)); mydata.Columns.Add("4k", typeof(int)); // Add the rows of data mydata.Rows.Add(new Object[] { "RC 50", 70, 65, 60, 55, 50, 45, 40 }); mydata.Rows.Add(new Object[] { "RC 45", 65, 60, 55, 50, 45, 40, 35 }); mydata.Rows.Add(new Object[] { "RC 40", 60, 55, 50, 45, 40, 35, 30 }); mydata.Rows.Add(new Object[] { "RC 35", 55, 50, 45, 40, 35, 30, 25 }); mydata.Rows.Add(new Object[] { "RC 30", 50, 45, 40, 35, 30, 25, 20 }); mydata.Rows.Add(new Object[] { "RC 25", 45, 40, 35, 30, 25, 20, 15 }); mydata.Rows.Add(new Object[] { "User Input", userInput[0], userInput[1], userInput[2], userInput[3], userInput[4], userInput[5], userInput[6] }); mydata.Rows.Add(new Object[] { "Rumble Limit", speechInterferenceLine + 25, speechInterferenceLine + 20, speechInterferenceLine + 15, speechInterferenceLine + 10, null, null, null }); mydata.Rows.Add(new Object[] { "Hissy Limit", null, null, null, null, speechInterferenceLine + 3, speechInterferenceLine + -2, speechInterferenceLine - 7 }); mydata.Rows.Add(new Object[] { "Reference Line", speechInterferenceLine + 20, speechInterferenceLine + 15, speechInterferenceLine + 10, speechInterferenceLine + 5, speechInterferenceLine, speechInterferenceLine - 5, speechInterferenceLine - 10 }); // Overriding user input line to be Orange Override override2 = new Override(); override2.Column = -2; // all columns override2.Row = 6; // User Input override2.PE = new PaintElement(Color.Orange); this.ultraChart1.Override.Add(override2); // Overriding rumble line to be red Override override3 = new Override(); override3.Column = -2; // all columns override3.Row = 7; // max permitted override3.PE = new PaintElement(Color.Red); this.ultraChart1.Override.Add(override3); // Overriding hiss line to be pink Override override4 = new Override(); override4.Column = -2; // all columns override4.Row = 8; // rumble limit override4.PE = new PaintElement(Color.Pink); this.ultraChart1.Override.Add(override4); // Overriding Reference lines to be green Override override5 = new Override(); override5.Column = -2; // all columns override5.Row = 9; // reference line override5.PE = new PaintElement(Color.Green); this.ultraChart1.Override.Add(override5); this.ultraChart1.InvalidateLayers(); ultraChart1.TitleTop.Text = path; return mydata; } }
The problem is that the graphs start to do unwanted things. Lines turn the wrong color when buttons are checked multiple times because it is still getting old information from last line overrides. Annotation are hard to read because they get thicker from not being erased from the last time, or annotation don't erase at all even though they are no longer relevant.
Thank you in advance.
Milko,
Thank you for the great response. Yes that solved part of the problem. I also need to override the annotations and lineappearances too. I don't see a method in Override to do that. Is there a way to override annotations and lineappearances too?
Amanda
Hello Amanda,
I have checked your example and this is what I found. When you create DataTable for your first chart, Make annotation for NC, you are adding override1 to UltraChart override collection. When you create data for your second chart, Make annotation for RC Speech Interference Level, you are adding four more overrides to override collection. In this way when you switch to your first chart you have five overrides in your override collection. What you can do is to clear override collection each time you switch the charts.
Please find attached a sample solution implementing what I wrote above.
Please let me know if this is what you are looking for or if I am missing something.