4

I have chart that can contain a lot of points (10000 +) When I scale the chart in order to see all points in screen, it takes some time to draw them

Scaled chart

Can You advice me some optimization, in order not to draw all points

Zlobaton
  • 664
  • 1
  • 9
  • 21
  • Is there any suspend method for the chart? Then you could suspend it while it resizes. – Aykut Çevik Apr 20 '11 at 13:39
  • suspend wont work, I need some mathematical solution in order to omit points that is not distinguished – Zlobaton Apr 20 '11 at 13:45
  • is there any zooming functionality? –  Apr 20 '11 at 13:48
  • what do you mean "zooming functionality"? – Zlobaton Apr 20 '11 at 13:51
  • 1
    well, de/increase the resolution of the x- and y- axis on the fly... eg. the whole width of your chart for 3:59 PM 'til 4:00PM ... on the fly... depending of the actual resolution you could calculate the points to skip - those which are not relevant for the resolution or those which are the equal to the previous –  Apr 20 '11 at 13:54

4 Answers4

7

I'm not an expert with listed technologies, but I would solve this by 'bucketing' your data points.

Your X axis is time, so determine the resolution point for the current chart size. IE, if you are seeing the entire chart you will only need a data point per day for example. If you are zoomed in a long way, you might want a point per hour.

Now you have determined resolution, go through your chart, and find all the data that exists between the resolution points, IE, all data that is > 20th April 2011 at 4pm and < 20th April 2011 at 5pm if you are on an hourly resolution.

Depending on the type of data you are using, will determine if you want to average all the data point you have collected, or find the median (or some other method, such as a candle stick chart to show the max/min values). Either way, pick the most relevant method, repeat for all points and render the result with your new data.

Hope that's what you meant.

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • you might want to add: skipping the points which are not caught by the resolution :) –  Apr 20 '11 at 13:58
3

Seems like you should use some sort of level of detail (LoD) algorithm.

For example: Always use a maximum given set of points to represent all your actual points. By calculating local minima and maxima you can create a proper representation of the given point set for a certain 'detail', depending on how far you are zoomed in.

Calculating these extrema can still prove to be slow, so you might need to cache them. You can calculate and cache this on the fly as new data arrives.

Steven Jeuris
  • 18,274
  • 9
  • 70
  • 161
  • hey, ... nice one ... know i know the name of my recommended "algorithm" :) thanks! –  Apr 20 '11 at 14:00
0

I had experienced a severe performance problem with thousands of Series added to the chart rather than thousands of Points. The solution that worked for me was a flavor of the Flyweight pattern:

  1. Instead of adding 1000-s of series, add just a single one.
  2. At the end of a virtual series, i.e., when all points of the series have been added and it's time to move on to the next one, insert an empty point:

    series.Points.Add(new DataPoint(0, 0) { IsEmpty = true });
    

Hope that helps somebody.

0

In addition to the other good suggestions, I would

  1. Do some random-pausing on it, to see if it's spending much time doing something else that could be avoided, such as maybe allocating new point structures all the time.

  2. Rather than paint directly to the window, paint to a bitmap, and copy that to the window. It always looks faster, and sometimes it even is faster. (Be sure to stub out the method that clears the window background.)

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135