i'm making a line chart and it's awesome.
but! (it's a little but)
the little colored indicators in my legend that tell me which series is which come out as lines, but i want them to come out as big fat squares like they do in the designer.
i've attached what they look like in the designer (which is what i want)
try checking the Row or the Column properties of the object named legendLine in the above code.
if that doesn't work, you could try something like this:
int nextPrimitiveIndex = e.SceneGraph.IndexOf(legendLine) + 1;
Text t = e.SceneGraph[nextPrimitiveIndex] as Text;
if (t != null)
{
Debug.WriteLine(t.GetTextString()); // this should be the legend label text
}
That's ALMOST working for me. How do I selectively apply these changes to only a few of the items in the legend? I have 7 series that appear in the legend, s5,s95,smean, sBudget5, sBudget95, sBudgetMean, and sActual. I want to add icons for s5,s95, and sMean, but not any of the others. I can't find the information I need to identify the corresponding series (or label in the legend). Any help is appreciated.
sir, you are a gentleman and a scholar. thanks very much.
unfortunately this can't be changed through a property setting; it is the difference between using the series collection as a datasource and using the datasource property ... that is, the legend behaves a little differently.
here's some code you can use as a FillSceneGraph event handler to remove the lines and replace them with boxes.
private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { PrimitiveCollection primitivesToAdd = new PrimitiveCollection(); PrimitiveCollection primitivesToRemove = new PrimitiveCollection(); foreach (Primitive p in e.SceneGraph) { if (p is Polyline && !string.IsNullOrEmpty(p.Path) && p.Path.Contains("Legend")) { Polyline legendLine = (Polyline)p; Point startPoint = legendLine.points[0].point; Point endPoint = legendLine.points[legendLine.points.Length - 1].point; Box newLegendIcon = new Box(startPoint, endPoint.X - startPoint.X, 5); newLegendIcon.PE = p.PE; newLegendIcon.PE.StrokeWidth = 1; primitivesToRemove.Add(legendLine); primitivesToAdd.Add(newLegendIcon); } } foreach (Primitive p in primitivesToRemove) { e.SceneGraph.Remove(p); } e.SceneGraph.AddRange(primitivesToAdd.ToArray()); }
however this is what they look like when i run the code
you see how they're little lines, and it's hard to tell what color it is?
how do i make them big, fat squares? i can't find the right property to tickle.