There are many questions on changing line appearances for line charts, but none quite fit what I want to do. I find it hard to believe I'm the only person that has wanted to do this, but I can't find the answer so...
In the following code I would like to change the line style for 9th row "hissy limit":
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 });
TO THIS:
// Overrideing to dashes LineAppearance lineApp3 = new LineAppearance(); lineApp3.LineStyle.DrawStyle = LineDrawStyle.Dash; lineApp3.LineStyle.MidPointAnchors = true; lineApp3.Thickness = 7; this.ultraChart1.LineChart.LineAppearances.Add(lineApp3);
Hello Amanda,
Thank you for contacting Infragistics.
Please see the following page in our documentation: http://help.infragistics.com/doc/WinForms/2014.1/CLR4.0/?page=Chart_Line_Appearances.html.
According to that page, you need to add a LineAppearance for each line you will have in the chart because the chart applies LineAppearances in a cyclical fashion. For example, if you have four lines and two line appearances, each line appearance will be used twice.
Please let me know if you have any other questions about this.
Dave,
Perhaps you could give me some code on how to do that, because as you can see I have found your page on Chart Line Appearance evidenced by the code I am trying to get to work per line as you suggested. The code I suggested that I needed to know how to implement is as copied from above:
// Overrideing to dashesLineAppearance lineApp3 = new LineAppearance();lineApp3.LineStyle.DrawStyle = LineDrawStyle.Dash;lineApp3.LineStyle.MidPointAnchors = true;lineApp3.Thickness = 7;this.ultraChart1.LineChart.LineAppearances.Add(lineApp3);
I have added 50 lines of code just to overwrite each line individual which seems unnecessary. Regardless now when I view the legend it does not indicate that the line should be dashed. I have one line that is red solid and one line that is red dashed and there is no legend difference between the two.
Amanda,
Thank you for your response.
I've attached a sample project which I believe does what you're looking for. In order to replace the default indicators in the legend, I had to handle the ChartDrawItem event and replace the primitive that was being used to draw them.
You may need to run the project through the Version Utility if you're not using the latest Service Release of Infragistics 2014 Volume 1. If you're not able to open the ".sln" file, then open the ".csproj" file instead.
Your code works exactly as I want it to work. However when I go to make the chart on my version it gives me a big red X instead of a chart.
In an effort to help you help me here is my code. I apologize that it is so long.
public partial class NCChart : Form { private int[] uI; private int noiseCriteria; private string newPath; private int roomCriteria;
public NCChart(int[] userInput, int NC, string path, int RC) { uI = userInput; noiseCriteria = NC; newPath = path; roomCriteria = RC; InitializeComponent(); this.ultraChart1.DataSource = GetColumnData(userInput, NC, path, RC); doOtherChartSpecializations(NC, path, RC); }
private DataTable GetColumnData(int[] userInput, int NC, string path, int RC) { if (radioButton1.Checked) { 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] }); doOtherChartSpecializations(NC, path, RC); ultraChart1.Data.RowLabelsColumn = 0; ultraChart1.Data.UseRowLabelsColumn = true; return mydata; } else { if (this.ultraChart1.Override.Overrides.Count != 0) { this.ultraChart1.Override.Overrides.Clear(); } 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 }); for (int i = 0; i < mydata.Rows.Count; i++) { var lineApp = new LineAppearance(); if (i == 8) { lineApp.LineStyle = new LineStyle(LineCapStyle.Round, LineCapStyle.Round, LineDrawStyle.Dash); } else { lineApp.LineStyle = new LineStyle(LineCapStyle.Round, LineCapStyle.Round, LineDrawStyle.Solid); } ultraChart1.LineChart.LineAppearances.Add(lineApp); } doOtherChartSpecializations(NC, path, RC); ultraChart1.Data.RowLabelsColumn = 0; ultraChart1.Data.UseRowLabelsColumn = true; return mydata; } }
private void button1_Click(object sender, EventArgs e) { printDialog1.Document = ultraChart1.PrintDocument; DialogResult res = printDialog1.ShowDialog(this); if (res == DialogResult.OK) { PrinterSettings printer1 = printDialog1.PrinterSettings;
PageSettings page1 = new PageSettings(); this.ultraChart1.PrintChart(printer1, page1); } }
private void button2_Click(object sender, EventArgs e) { this.Visible = false; this.Close(); RCChart form = new RCChart(uI, noiseCriteria, newPath, roomCriteria); form.ShowDialog(); }
private void radioButtons_CheckedChanged(object sender, EventArgs e) { this.ultraChart1.DataSource = GetColumnData(uI, noiseCriteria, newPath, roomCriteria); this.ultraChart1.DataBind(); ultraChart1.Update(); } /* private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { // here we are catching all lines except User Input line var polyLines = e.SceneGraph.OfType<Polyline>().Where(p => !(p.Row == 6 && p.Column == 6)).ToList();
if (polyLines.Count == 0) { return; }
foreach (var polyLine in polyLines) { foreach (var point in polyLine.points) { point.Caps = PCaps.None; } } } */ private void ultraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e) { if ((e.Primitive is Box) && (e.Primitive.Path.Contains("Legend")) && (e.Primitive.Row >= 0)) { var box = e.Primitive as Box; var p1 = new Point(box.rect.Left, (box.rect.Top + (box.rect.Height / 2))); var p2 = new Point(box.rect.Right, (box.rect.Top + (box.rect.Height / 2))); var line = new Line(p1, p2); line.PE.Fill = box.PE.Fill; line.PE.Stroke = box.PE.Fill; line.PE.StrokeWidth = 2; line.lineStyle = ultraChart1.LineChart.LineAppearances[e.Primitive.Row].LineStyle; e.Primitive = line; } }
private void doOtherChartSpecializations(int NC, String path, int RC) { ultraChart1.TitleTop.Text = path; if (radioButton1.Checked) { if (this.ultraChart1.Override.Overrides.Count != 0) { this.ultraChart1.Override.Overrides.Clear(); } // 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(); // 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); }
else { if (this.ultraChart1.Override.Overrides.Count != 0) { this.ultraChart1.Override.Overrides.Clear(); } // 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(); // 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.Red); 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); } } }
Amanda
So it seems the problem was that the data wasn't being created before the chart was trying to draw the new legend.
It was fixed by doing the following:
private void radioButtons_CheckedChanged(object sender, EventArgs e) {
if (this.ultraChart1.Override.Overrides.Count != 0) { //removes all overrides this.ultraChart1.Override.Overrides.Clear(); // removes all annotations this.ultraChart1.Annotations.Annotations.Clear(); } if (radioButton2.Checked) { ultraChart1.LineChart.LineAppearances.Clear(); // Make line dashed for rumble limit for (int i = 0; i < 10; i++) { var lineApp = new LineAppearance(); if (i == 8) { lineApp.LineStyle = new LineStyle(LineCapStyle.Round, LineCapStyle.Round, LineDrawStyle.Dash); } else { lineApp.LineStyle = new LineStyle(LineCapStyle.Round, LineCapStyle.Round, LineDrawStyle.Solid); } ultraChart1.LineChart.LineAppearances.Add(lineApp); }
// Must do to set up data at the end of completing new chart setUpData(); } else if (radioButton1.Checked) { ultraChart1.LineChart.LineAppearances.Clear(); //MessageBox.Show("things that work are awesome."); // Make line dashed for rumble limit for (int i = 0; i <= 11; i++) { var lineApp = new LineAppearance(); lineApp.LineStyle = new LineStyle(LineCapStyle.Round, LineCapStyle.Round, LineDrawStyle.Solid); ultraChart1.LineChart.LineAppearances.Add(lineApp); }
// Must do to set up data at the end of completing new chart setUpData(); } }
private void setUpData() { this.ultraChart1.DataSource = GetColumnData(uI, noiseCriteria, newPath, roomCriteria); this.ultraChart1.DataBind(); }
// New method for data set up to be run at the correct time
private void ultraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e) { if ((e.Primitive is Box) && (e.Primitive.Path.Contains("Legend")) && (e.Primitive.Row >= 0)) { var box = e.Primitive as Box; var p1 = new Point(box.rect.Left, (box.rect.Top + (box.rect.Height / 2))); var p2 = new Point(box.rect.Right, (box.rect.Top + (box.rect.Height / 2))); var line = new Line(p1, p2); line.PE.Fill = box.PE.Fill; line.PE.Stroke = box.PE.Fill; line.PE.StrokeWidth = 2; // This is necessary because this may be // called before new chart data has been set. if (ultraChart1.LineChart.LineAppearances.Count > e.Primitive.Row) { line.lineStyle = ultraChart1.LineChart.LineAppearances[e.Primitive.Row].LineStyle; e.Primitive = line; } } }
The main difference between the sample and my own is that I have 2 charts appearing with different legends. The charts are selected by checking a radio button. Would this make a difference?
var box = e.Primitive as Box; var p1 = new Point(box.rect.Left, (box.rect.Top + (box.rect.Height / 2))); var p2 = new Point(box.rect.Right, (box.rect.Top + (box.rect.Height / 2))); var line = new Line(p1, p2); line.PE.Fill = box.PE.Fill; line.PE.Stroke = box.PE.Fill; line.PE.StrokeWidth = 2; line.lineStyle = ultraChart1.LineChart.LineAppearances[e.Primitive.Row].LineStyle; e.Primitive = line;
When this part is left out the chart is drawn. It does not draw the way I want but that is a question for later. Although infragistics is up to date the program is being made in VS 2008. Would this cause these lines of codes not to work and what part?
Version 14.1. It does not happen to the helper file supplied, but does happen to my file. This tells me that something in my code is not working properly with the suggestion and it has nothing to do with the version of infragistics I am using. Sorry for the delayed response I have been away for awhile.
I am following up to see if you still need assistance with this issue.
If you no longer need assistance, please follow up and let us know how you resolved the issue.