In a program, I want to show a movie and the audience ratings at the same time. So I created a little movie player with a LineChart on it. During the movie plays, a slider moves from left to right. In order to illustrate the current position, I place a vertically line on the chart, which is on the same position as the slider.
The processing:1. A timer control fires every 10 ms.2. In the timer_tick event, I reposition the slider button and invalidate the chart (via InvalidateLayers)3. InvalidateLayers causes the FillSceneGraph event.4. Inside FillSceneGraph I paint a red line. Here the source code:
public void Chart_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e){ IAdvanceAxis axisX = e.Grid["X"] as IAdvanceAxis; IAdvanceAxis axisY = e.Grid["Y"] as IAdvanceAxis; double dLength = (double)axisX.Maximum - (double)axisX.Minimum; int xStart = (int)axisX.Map((int)(dLength * _Movie_Track.Value / _Movie_Track.Maximum)); int xEnd = xStart; int yStart = (int)axisY.Map(axisY.Minimum); int yEnd = (int)axisY.Map(axisY.Maximum); _targetLine = new Line(new Point(xStart, yStart), new Point(xEnd, yEnd)); _targetLine.PE.Stroke = Color.Red; _targetLine.PE.StrokeWidth = 1; e.SceneGraph.Add(_targetLine);}
It works ok, but with big data (3 series, each 30000 datapoints) it works quite slow (plobably due to the multiple InvalidateLayer calls). So my question:Is this the recommended way to do this or is there another (faster) alternative?
Every time you need to reposition the line, you will have to re-render the chart control, so I'm afraid there's no way around calling InvalidateLayers.
Your only option to improve performance is to determine whether or not the line needs to be moved and selectively invalidate the layers. For example, if you have 30000 points and a time span of 10ms, chances are, the line will have to be moved by less than one pixel. So, in this case it doesn't make sense to re-invalidate and move the line at all.
Thank you for your advise.
When do I know, if a line has to be moved by one pixel?
Is there a property or something like that how long (in pixel) the x-axis is?
Thanks in advance
Thank you very much. I will try it out.
In FillSceneGraph, once you get the reference to the axis, use axis.MapRange to find the axis size in pixels.
IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"];double range = xAxis.MapRange;
The line screen location can be calculated using xAxis.Map(someAxisValue)