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

Message ListMessage List     Post MessagePost Message

  MFC Customize XyChart to Show Grid or Not
Posted by Sal on Jun-13-2015 00:05
Attachments:
Peter,

I use your V6 Library to show Images of object been scanned (Expanding the Library usage it was designed for)
For clarity, at times I need to remove most of the artificial lines been added to chart by the Grid Operation, but retain the Axis Ruler Inage

I partially was successful - Please see Image I am supplying

The Top Image is what in one case I need to show with the Grid been On (100% correct)
The Bottom Image, is the result of the same code that creates the above image with some minor changes to the ChartDir API methods I call, to remove the viewing of the grid

As you notice, I have 4 issues I have not been able to resolve:

Q1: How to remove the Top and Right Plot Area Margin Border lines
Q2: The intermediate Y value (In Gray is not been show) - I would like to see it
Q3: The intermediate Tic Mark at that Y position is not shown in Gray
Q4: Similar to (3) for the Horizontal Axis: Mid Tick mark in between values shown in Black

This is My Code about what I tried:
(Some code sections left out since not related to the issues I am asking about)

I expanded your class code to create some "Custom" drawing methods, to make my code more re-usable (MyChartArea) across different my applications

-------

      pXyChart = new XYChart(iDrawingWidth, iDrawingHeight, TextureOusideChart, ColorOusideChart);

int iRoomToLabelAxis = 15; // This creates room to label Vert. axis with 2 labels
int iHzMargin = iRoomToLabelAxis + 45; // At the bottom
int iLeftMargin = iHzMargin;
int iRightMargin = iHzMargin;
int iTopMargin = 2 * iBoxHeight;         // Since we label the View (top)

        int iBottomMargin = 2 * iBoxHeight; // Since we Label the Hz. Axis

MyChartArea.SetChartMarginArea(iTopMargin, iLeftMargin, iBottomMargin, iRightMargin);

// Room occupied by Axis is calculated above
int iXAxisSizeInPixels;
int iYAxisSizeInPixels;
MyChartArea.GetAxisLenghtSizeInPixels(&iXAxisSizeInPixels, &iYAxisSizeInPixels);

        // Turn on both horizontal and vertical grid lines with light grey color +
// Fill Graph area with same texture and color as surrounging color area (Plot area)
PlotArea* pPlotArea =  MyChartArea.SetPlotArea(MyChartArea.GetTextureOusideChart(), bShowGrid);

// Label the Hz. axis w/Profile ID been Viewed and its Location
Axis* pAxisX = c->xAxis();
IdentifyProfile(pDoc, &brd_data, iLaserNum, iLengthOption, sz);
MyChartArea.SetAxis(pAxisX, sz.GetBuffer(), "arialbi.ttf", 12, 2);

       // This make the Major tics longer than minor
pAxisX->setTickLength(10, 5);

// Label the Vr. axis
Axis* pAxisY = c->yAxis();
MyChartArea.SetAxis(pAxisY, "Lead Edge", "arialbi.ttf", 12, 2);

        // This defines the Major tics longer than minor
        pAxisY->setTickLength(10, 5);

// Grid lines at that location are optionally added later on
if (!bMaximizeWidthViewing)
pAxisX->setLinearScale(dLimits.dMinX, dLimits.dMaxX, 1.0, 0.250); // Since Axis covers more Hz. range
else
pAxisX->setLinearScale(dLimits.dMinX, dLimits.dMaxX, 1.0, 0.125); // Since Axis can show more details about piece

pAxisY->setLinearScale(dLimits.dMinY, dLimits.dMaxY, 1.0, 0.125); // Since Axis covers less Vr. range

// Add additional Mark + Label to the Vertical axis
// Labeling every intermediate tic division marks between whole Inches Mark
int iLineColorForInBetweenMajorTic = MyChartArea.GetLineColorForInBetweenMajorTic(); // Dark Gray

for (double dY=dLimits.dMinY + 0.5; dY < dLimits.dMaxY; dY += 1)
{
sz.Format("%2.1f", dY);

if (bShowGrid)
pAxisY->addMark(dY, iLineColorForInBetweenMajorTic, sz.GetBuffer());
else
pAxisY->addMark(dY, Chart::Transparent, sz.GetBuffer()); // No Grid line been drawn
}

// Add additional Marks to the Horizontal axis
if (!bMaximizeWidthViewing)
{
// Since the Axis plots a large range, limit the Label to Major tics only
// Add the Line in between Major tic marks, but do not label the addition
for (double dX=dLimits.dMinX + 0.5; dX < dLimits.dMaxX; dX += 1)
{

if (bShowGrid)
pAxisX->addMark(dX, iLineColorForInBetweenMajorTic);
else
pAxisX->addMark(dX, Chart::Transparent);
}
}
else
{
for (double dX=dLimits.dMinX + 0.5; dX < dLimits.dMaxX; dX += 1)
{
// Add the Line in between Major tic marks + Label the Addition
sz.Format("%2.1f", dX);

if (bShowGrid)
pAxisX->addMark(dX, iLineColorForInBetweenMajorTic, sz.GetBuffer());
else
pAxisX->addMark(dX, Chart::Transparent, sz.GetBuffer());
}
}

------

PlotArea* CMyChartViewer::SetPlotArea(COLORREF cRef, BOOL bShowGrid)
{

if (bShowGrid)
{
pPlotArea = pXyChart->setPlotArea( iLeftMargin, iTopMargin,
iXAxisSizeInPixels,
iYAxisSizeInPixels,
Chart::Transparent, -1, 0xc0c0c0, 0xc0c0c0, -1);

         // Define Color of Lines in Grid (Major: Black, Minor: Light Gray)
pPlotArea->setGridColor(0, 0, 0xc0c0c0, 0xc0c0c0);
}
else
{
pPlotArea = pXyChart->setPlotArea( iLeftMargin, iTopMargin,
iXAxisSizeInPixels,
iYAxisSizeInPixels,
Chart::Transparent, -1, Chart::Transparent, Chart::Transparent, Chart::Transparent);
}

// Use default color if not specified
pPlotArea->setBackground(cRef);

return pPlotArea;
}

------------

One idea I had, was to trace over the existing line (TOP + Left Line) using the DrawArea methods built in Methods and create those elements missing from the 2nd Graph

I was wondering If I would be re-inventing what already exists because I am not using the correct API and its methods correctly

Any suggestions ?

Thanks
Sal
Image 06 Jun. 12, 2015.jpg

  Re: MFC Customize XyChart to Show Grid or Not
Posted by Sal on Jun-13-2015 01:54
Peter,

I was able to resolve the last 3 Issues I was asking about

For those of you that might be interested this is the trick that hides the Grid Lines, and show the Mark Value and thenTic Mark:

-----

sz.Format("%2.1f", dY);

if (bShowGrid)
pAxisY->addMark(dY, iLineColorForInBetweenMajorTic, sz.GetBuffer());
else
{
Mark* pMark = pAxisY->addMark(dY, Chart::Transparent, sz.GetBuffer()); // No Grid line been drawn
pMark->setMarkColor(Chart::Transparent, iLineColorForInBetweenMajorTic, iLineColorForInBetweenMajorTic);
}

--------

I am still at a loss for Question 1, where I definitively I need some help

Thanks for anything direction on the matter you can supply
Sal

  Re: MFC Customize XyChart to Show Grid or Not
Posted by Peter Kwan on Jun-13-2015 02:14
Hi Sal,

The line in Question 1 is the plot area border. Although the setPlotArea line in your code has
set the plot area border to transparent, later your code calls setBackground which sets the
plot area border to the default line color (black). So at the end, the plot area border is
black.

The line is question is:

pPlotArea->setBackground(cRef);

The setBackground accepts 3 arguments, of which the last argument is the plot area
border. According to the documentation, if this argument is not provided, its default value is
the default line color.

For your case, you may use:

pPlotArea->setBackground(cRef, cRef, Chart::Transparent);

Hope this can help.

Regards
Peter Kwan