Hello,
I have a problem with Legend in LineChart (Rf: Picture). I add some Series with Color but the correspondant Color in Legend are different. I try using FillSceneGraph and ChartDrawItem like in some example here in Forum but i didnt work:
static void UltraChart_ChartDrawItem(object sender, ChartDrawItemEventArgs e) { if (e.Primitive is Polyline || (e.Primitive is Box && e.Primitive.Path != null && e.Primitive.Path.IndexOf("Legend") != -1)) { if (e.Primitive.Series != null) { if (e.Primitive.Series.Label == "Sparkasse i.Zshg.m. Produkt-, Unternehmensmeldungen") e.Primitive.PE = new PaintElement(Color.Red); if (e.Primitive.Series.Label == "Deutsche Bank i.Zshg.m. Produkt-, Unternehmensmeldungen") e.Primitive.PE = new PaintElement(Color.Blue); if (e.Primitive.Series.Label == "Dresdner Bank i.Zshg.m. Produkt-, Unternehmensmeldungen") e.Primitive.PE = new PaintElement(Color.Green); if (e.Primitive.Series.Label == "Postbank i.Zshg.m. Produkt-, Unternehmensmeldungen") e.Primitive.PE = new PaintElement(Color.YellowGreen); if (e.Primitive.Series.Label == "Commerzbank i.Zshg.m. Produkt-, Unternehmensmeldungen") e.Primitive.PE = new PaintElement(Color.Yellow); } } }
Any Solutions are welcome.
Thanks
probably e.Primitive.Series is going to be null there.
try this instead:
private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { for (int current = 0; current < e.SceneGraph.Count; current++) { Primitive currentPrim = e.SceneGraph[current]; bool legendBox = currentPrim is Box && currentPrim.Path != null && currentPrim.Path.Contains("Legend") && currentPrim.Row == 0; if (legendBox && current < e.SceneGraph.Count - 1) { Text nextLabel = e.SceneGraph[current + 1] as Text; if (nextLabel != null) {
string nextLabelText = nextLabel.GetTextString();// do what you want here based on the text in the legend label } } }