ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Is makeChart() ever called twice on a chart?
Posted by David Wilson on May-31-2019 07:48
Thank you for your kind and prompt help in the past.

In our application, we generate animated charts in real time, drawing charts on the screen several times a second, so it is advantageous to avoid extra work. I am fully aware that CD does not support animation, and I am not asking for such support, but I would like to know one thing.

I understand that makeChart() creates and lays out chart elements in their final locations on the chart (given the page dimensions).  makeChart() is a moderately expensive call, moreso for more complex charts.

For our simpler charts, the chart creation logic is

    // Create a chart
    // Add chart elements
    auto memblock = chart.makeChart(BMP);

In this case, it makes sense that makeChart(BMP) must call makeChart() or equivalent to lay out chart elements before creating the BMP memory block.

For other charts that require graphical elements, our logic is

    // Create a chart
    // Add chart elements
    auto drawarea = chart.makeChart()
    // Add graphical elements to the draw area
   auto memblock = chart.makeChart(BMP);

So I'm wondering, in this case, does makeChart(BMP) check that makeChart() was already called and skip layout of graphical elements, or does it perform the layout a second time?

Many thanks in advance.

Dave Wilson

  Re: Is makeChart() ever called twice on a chart?
Posted by Peter Kwan on May-31-2019 17:30
Hi David,

You can use the DrawArea to add things to the chart after calling makeChart. If you call makeChart again, it will not re-layout the chart, so it is efficient.

Note that the DrawArea can only add things to the chart. It cannot delete things. For animation (such as moving a point), you need to delete the point at the old position and redraw the point in its new position. There are two methods:

(a) Use the dynamic layer. See the "Programming Track Cursor" sample code.

(b) Just redraw the entire chart. For many charts, ChartDirector is fast enough to draw several charts per second. All our Zooming and Scrolling examples use complete chart redraw. When you use the move wheel to zoom in/out, the chart is repeated redrawn quite a number of times per second.

About animation, I remember we have an example written for one of our customers quite a while ago. It animates a contour chart, which is the most CPU intensive XYChart type. It simply redraws the chart many times per second, and can archive "smooth animation". May be you can take a look. The download includes both single-threaded and multi-threaded versions of the animated heat map. It is written in C# and the download includes the ChartDirector for .NET assembly, so you can just download and compile and run. I think it should run even faster if ported to C++.

http://www.advsofteng.com/heatmapanimation.zip

Regards
Peter Kwan

  Re: Is makeChart() ever called twice on a chart?
Posted by David Wilson on Jun-03-2019 20:47
Thank you for your prompt response.

Our application already performs animation by redrawing the chart.

I did have another question, though.

When you make multiple calls to makeChart(fileFormat), for example, makeChart(BMP), does each call allocate the memory block for the image data, or does it reuse memory from previous calls?

  Re: Is makeChart() ever called twice on a chart?
Posted by Peter Kwan on Jun-04-2019 00:18
Hi David,

For C++, it reuses the previous memory block if it is of sufficient size. (For BMP, every output is of the same size as it can always reuse the memory.) It means the output of makeChart(fileFormat) will be valid until the next makeChart call or until the chart object is deleted, whichever occurs earlier.

Regards
Peter Kwan