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);
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.
Hello Amanda,
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.