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

Message ListMessage List     Post MessagePost Message

  DrawArea line not working well with scroll/track chart
Posted by david on Nov-14-2020 22:42
Attachments:
Hello,

I'm trying to draw a line using DrawArea on top of scroll-able chart (the zoomscrolltrack example). My test code modifies CChartViewer::setChart by adding DrawArea after makeChart. However, the line flickers (disappears sometimes) when I scroll the chart or move mouse on the chart. I checked the code and found a delayed update may cause the issue. So how to draw objects in this case? Thanks!

void CChartViewer::setChart(BaseChart *c)
{
if ((GetStyle() & SS_NOTIFY) == 0)
ModifyStyle(0, SS_NOTIFY);
if ((GetStyle() & SS_TYPEMASK) != SS_BITMAP)
ModifyStyle(SS_TYPEMASK, SS_BITMAP);

m_currentChart = c;
setImageMap(0);

if (0 != c)
{
commitPendingSyncAxis(c);
        if (m_delayUpdateChart != NO_DELAY)
        {
            DrawArea* d = c->makeChart();
            d->line(1, 50, 500, 500, 0x000000, 5);
        }
}

updateDisplay();
}
Screen Shot 2020-11-14 at 10.35.42 PM.png
Screen Shot 2020-11-14 at 10.36.00 PM.png

  Re: DrawArea line not working well with scroll/track chart
Posted by Peter Kwan on Nov-16-2020 23:13
Hi David,

I am not sure what is your intention. If you just want to have a line on the chart image, you can add it before you call setChart, like:

DrawArea* d = c->makeChart();
d->line(1, 50, 500, 500, 0x000000, 5);

viewer.setChart(c);

If for some reasons, you want to add the code inside setChart, you can add it before
"if (m_delayUpdateChart != NO_DELAY)", like:

DrawArea* d = c->makeChart();
d->line(1, 50, 500, 500, 0x000000, 5);

// Keep the original code unchanged
if (m_delayUpdateChart != NO_DELAY)
   c->makeChart();


The purpose of m_delayUpdateChart is to temporary suspend updating the chart. It is because a single action trigger multiple events to update the display multiple times. For example, if the mouse is dragged to scroll the chart, the chart will update in the ViewPortChanged event. The track cursor will also be updated in the MouseMovePlotArea event. The CChartViewer will only update the display after all events are processed.

If your intention is to draw something interactively on the chart, I suggest you draw on the dynamic layer, just like how the track cursor is drawn.

Regards
Peter Kwan

  Re: DrawArea line not working well with scroll/track chart
Posted by david on Nov-17-2020 11:53
This works. Thanks!