Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
How to visualize the current position of a movie in a LineChart dynamically?
posted

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?

 

 

Parents
  • 26458
    Offline posted

    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.

Reply Children