I have a simple LineChart with one or more lines with various data points. I need to be able to manipulate back or fore color of the data points in each of the lines. What is the simplest way to do something like that? I would appreciate a code snippet. Picture below demonstrate the functionality that I need to implement (highlighting of certain data points).Thanks.
Thanks so much! This is exactly what I needed.
I think in this scenario, I wouldn't recommend using ChartText. Labels don't really have backgrounds, but with a little magic in FillSceneGraph event you can work around the issue:private void Form1_Load(object sender, EventArgs ev){ ultraChart1.ChartType = ChartType.LineChart; ultraChart1.Data.DataSource = new int[,] { { 1, 2, 3, 4, 2, 3, 1, 5 } };}
private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e){ Polyline line = null;
foreach (Primitive p in e.SceneGraph) { if (p is Polyline) { line = p as Polyline; break; } }
if (line == null) return;
foreach (DataPoint point in line.points) { Text label = new Text(); string str = point.Value.ToString(); label.SetTextString(str); SizeF labelSize = Platform.GetLabelSizePixels(str, label.labelStyle);
Rectangle bounds = new Rectangle( point.point.X - (int)labelSize.Width / 2, point.point.Y - (int)labelSize.Height, (int)labelSize.Width, (int)labelSize.Height);
label.bounds = bounds;
Box background = new Box(bounds); background.PE.Fill = Color.Yellow; background.PE.StrokeWidth = 0;
e.SceneGraph.Add(background); e.SceneGraph.Add(label); }}
If you also want some conditional highlighting, don't add the box to the scenegraph for the point you want to skip
Clarification - picture above shows a line chart with certain data points highlighted. I need to reproduce the same functionality in code. There must be a way to set back/forecolor for the data points on the graph. Is that something that never came up before?