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.
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.