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

Message ListMessage List     Post MessagePost Message

  vline or line on MultiChart not showing
Posted by BrunoVoisin on Mar-14-2024 21:19
Hi,

I have a MultiChart object with 3 charts, and I want to draw a vertical line on the 1st one.
The graph looks fine but a simple vline call returns nothing.
The test value here 5200 exists on the graph.

Here is a code sample:

MultiChart m = (MultiChart) winChartViewer3.Chart;
XYChart c = (XYChart)m.getChart(0);

int redcolor = 0xff0000;
double value = 5200;                                // Test X value
int onesd = c.getXCoor(value);

int offsetY = c.getAbsOffsetY();
PlotArea pa = c.getPlotArea();
int top = pa.getTopY();
int bot = pa.getBottomY();
DrawArea d = m.initDynamicLayer();         // Obtain the dynamic layer of the MultiChart
d.line(top + offsetY, bot + offsetY, onesd, redcolor, 2);
//d.vline(top + offsetY, bot + offsetY, onesd, redcolor);
Console.WriteLine("Vertical from " + top + " to " + bot + " (Offset: " + offsetY + ") " + onesd);

What am I doing wrong ?
Thanks in advance.

  Re: vline or line on MultiChart not showing
Posted by Peter Kwan on Mar-15-2024 01:15
Hi BrunoVoisin,

Have you called winChartViewer3.updateDisplay() ?

You can draw many things on the dynamic layer. ChartDirector will not update the display until you have completed the drawing, but it cannot know when you have completed the drawing. The updateDisplay API is to tell ChartDirector it is OK to update the display.

Best Regard
Peter Kwan

  Re: vline or line on MultiChart not showing
Posted by BrunoVoisin on Mar-15-2024 16:26
Thank you Peter.
I have now added updateDisplay() as suggested, to no difference, however.
I have also copied some code (DrawMultiTrackLine) from the sample and vline works with the current mouse position, so this issue of mine is puzzling...
Regards,
Bruno

  Re: vline or line on MultiChart not showing
Posted by Peter Kwan on Mar-15-2024 18:22
Hi BrunoVoisin,

I look at your code more carefully. I found that the d.line should be incorrect. The d.line requires the two ends points of the line (x1, y1, x2, y2 ...), but your code passes in (y1, y2, x1) as the coordinates. It should be:

d.line(onesd, top + offsetY, onesd, bot + offsetY, redcolor, 2);

If the above still cannot solve the problem, please try using hard coded data:

d.line(100, 20, 100, 80, 0xff0000, 2);

With the above, a red line should be drawn somewhere (assuming your MultiChart is larger than 100 x 80 in size). This can test whether it is the problem with the drawing code or with the coordinates used (especially the "onesd").

Best Regards
Peter Kwan

  Re: vline or line on MultiChart not showing
Posted by BrunoVoisin on Mar-15-2024 19:53
Thank you Peter,
The d.line code was indeed incorrect, however I am choosing to only use d.vline for now.
I think I have found what went wrong (my bad!): the vertical line I draw with d.vline is immediately erased by the redrawing code in the mouse event.
Best regards,
Bruno