|
Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Sal on Jun-11-2015 00:21 |
|
Hello Peter,
I am trying to create an area by connecting a set of 4 Points in a XyChart
I tried using the following:
LineLayer* pLineL = c->addLineLayer(DoubleArray(dY, nPoints), cRef);
pLineL->setXData(DoubleArray(dX, nPoints));
pLineL->setLineWidth(iBorderWidthInPixels);
This draws 3 Sides of an open polygon
To Close the above, I must supply the Initial Point again, so in practice I am connecting lines in between 5 points, where the first + last are the same
Repeated the above with the intention of Filling the enclosed area with some color
I used the following code
AreaLayer* pAreaL = c->addAreaLayer(DoubleArray(dY, nPoints), cRef);
pAreaL->setXData(DoubleArray(dX, nPoints));
pAreaL->setLineWidth(iBorderWidthInPixels);
As before I had specify at the end of the Series the Initial point
The Area is filled, but I have something extra been added to the chart as I show in the chart I attached to this request of clarification
My chart is used in conjunction with a ViewPort, that appears to be functioning correctly
I do not see what I am doing wrong, that is producing the extra line
It is like that extra line been drawn is part of the logic to track mouse position and display its coordinate, that I decided to exclude from my code (The X axis is shown the Y is not)
I have an un-usual coordinate system, but the issue is still there with a normal coordinate system
Any ideas of what I might be doing wrong ?
Thanks
Sal |
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Sal on Jun-11-2015 00:33 |
|
It looks like I am having trouble sending a sample of what My chart looks like....
|
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Peter Kwan on Jun-11-2015 00:43 |
|
Hi Sal,
For some reasons, I cannot see the attachment.
Note that an area layer is to fill the region between the area line and the x-axis. I have
attached an example that shows how the area layer works. It contains 5 data points (the
red dots). Note that the border of the area includes the vertical line that connects the first
and last points to the x-axis. You can disable the lines by setting the area border line color
to transparent. If you think the line layer border is the one you want, you can add a line
layer to create the border.
Regards
Peter Kwan
|
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Peter Kwan on Jun-11-2015 00:58 |
|
Hi Sal,
I can see your attachment now. (I wrote my last response before seeing your latest post.)
The line is the line joining the first and last points to the "base line" (the line at y = 0, or
the border of the plot area that is closest to y = 0). Also, although the filling seems to work
in your particular case, I am not so sure if the area layer will work for a general polygon, as
it is supposed to fill the region between the area line and the base line. For a general
polygon, the DrawArea.polygon method should be used. An example is like:
... add a dummy transparent layer contain the data points, so that when
... ChartDirector auto-scales the axis, it will include the proper data range
// Now draw the chart
DrawArea *d = c->makeChart();
// Add a custom polygon on the chart. The XYChart.getXCoor and XYChart.getYCoor can
// be used to translate from data values into pixel coordinates for DrawArea.polygon
d->polygon(.......);
Regards
Peter Kwan |
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Sal on Jun-11-2015 02:35 |
|
Thanks for all your help
It worked exactly as you described
Sal |
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Sal on Jun-11-2015 22:50 |
|
Peter,
I have One follow-up question to this topic
Q1:
Once I added the code you suggested, I noticed that moving the dialog outside the Monitor in which it appeared the first time, did not redraw the added area.
The Grid and anything else that was added to the graph was there, not the Polygon(s) I added manually using the technique you suggested
To correct the issue, I changed the code slightly as I show in here:
// DrawArea* d = c->getDrawArea();
DrawArea* d = c->makeChart(); // Suggested by Peter in place of the above
// Set the chart image to the WinChartViewer
delete pViewer->getChart();
pViewer->setChart(c); // Output the chart
// This section must follow the previous section
// Complete the Drawing by overlaying the Obstruction area, by converting the World Points coordinates to Pixels
if (iNumObstructions > 0)
{
int ptX[MAX_NUM_POINTS_TO_PLOT_AREA];
int ptY[MAX_NUM_POINTS_TO_PLOT_AREA];
for (int n=0; n < iNumObstructions; n++)
{
for (int i=0; i < MAX_NUM_POINTS_TO_PLOT_AREA; i++)
{
ptX[i] = c->getXCoor(ObstructionX[n][i]);
ptY[i] = c->getYCoor(ObstructionY[n][i]);
}
d->polygon(IntArray(ptX, MAX_NUM_POINTS_TO_PLOT_AREA), IntArray(ptY, MAX_NUM_POINTS_TO_PLOT_AREA), 0x00000000, 0x80000000 | m_PlotArea.GetObstructionColor(n));
}
m_PlotArea.updateDisplay(); // It corrects the Issue about the polygon been lost and not been visible at times
}
Though the results are what I wanted, I was wondering why I had to do the above.
Can you help me to understand ?
I was of the understanding that actions to the "DrawArea" class are immediate, because I draw over the Graph which is already been made visible.
I must be mistaken...
Thanks
Sal |
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Peter Kwan on Jun-12-2015 01:10 |
|
Hi Sal,
To display anything on the screen, the MFC and Windows must move the graphics to the
screen frame buffer (some sort of RAM in the video card or video system, which is
different from the RAM used in running programs).
Your code can update the chart, and the update will be reflecting directly in program
memory, but MFC/Windows may not know that it needs to copy them to the frame
buffer. So the screen is not updated.
ChartDirector will not automatically tell MFC/Windows to update the screen buffer when
things are drawn using DrawArea. It is because drawing typically contains many steps.
For example, the code may draw several polygons, then add some lines, symbols and
text in other places, etc. (If you have tried the "track cursor" code, you can see a track
cursor is drawing with many steps.) If the screen buffer is updated for every single
change, the overhead will be too large, and you may see some half-completed drawing on
the screen. Instead, the drawing code should call "updateDisplay" to notify ChartDirector
that the drawing has been completed, and that it can be displayed.
For the setChart, when this method is called, ChartDirector automatically assume the
chart is completed and your code intend to display it. So for setChart, no updateDisplay
is necessary. That's why in our code, setChart is always the last step.
For your case, you may consider to put the "delete pViewer->getChart();" and "pViewer-
>setChart(c);" code after your code has completed the drawing. I think it is also the
intention of your code that it displays a completed drawing, rather than an incomplete
drawing followed quickly by a complete drawing.
Regards
Peter Kwan |
Re: Creating an empty area by connecting points vs. Same Points in a Filled Area |
Posted by Sal on Jun-12-2015 03:27 |
|
Thanks for the last reply
Also thanks for catching the "delete pViewer->getChart() and pViewer->setChart()" as been out of place
I was wondering why only those items drawn using the DrawArea class were flickering.
Once I put the above 2 lines after the creation, as correctly you assumed I wanted to do, the defect went away
Thanks a million
Great technical support !!!
Sal |
|