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

Message ListMessage List     Post MessagePost Message

  hello
Posted by shila on Jan-06-2009 18:43
Thanks for your reply..

But still im having probs.
Its not showing horizontal grids.

below is code
        XYChart *c = new XYChart(iCX, iCY);
        if(m_IsGridOn == TRUE)
       {
// Set the plotarea
c->setPlotArea(Rect.left,   // x40
                     Rect.top,    // y80
        Rect.right - m_Rect.left,     // width
        Rect.bottom - m_Rect.top,  // height
-1,                             // bgColor
-1,                             // altBgColor
Chart::Transparent,          // edgeColor
c->dashLineColor(0xcccccc, Chart::DashLine), // hGridColor
c->dashLineColor(0xcccccc, Chart::DashLine)); //vGridColor
     }

        // Enable clipping mode to clip the part of the data that is outside the plot area.
        c->setClipping();

        // Drawing a grid line on top edge of the y axis.
        c->addLine( m_Rect.left - 8, m_Rect.top,
            m_Rect.left - 3, m_Rect.top ,0xFFFF0001, 1);
        c->addLine( m_Rect.left + 3, m_Rect.top,
            m_Rect.left + 8, m_Rect.top ,0xFFFF0001, 1);

        // Add a titles to axes
        c->xAxis()->setTitle(" ");
        c->yAxis()->setTitle(" ");

Can you please reply soon...
its very critical

  Re: hello
Posted by Peter Kwan on Jan-07-2009 01:10
Hi shila,

In your case, I can only think of 2 reasons why there will be no vertical grid lines.

(a) There is no ticks on the x-axis to draw the grid lines.

ChartDirector will not draw the grid lines at random positions. It will draw them on major and/or minor tick positions. If there is no tick on the axis, there will be no place to draw the grid lines. You will need to use setLabels or setLinearScale, or use auto-scaling, etc., to set up an x-axis that has ticks. (If you do not want to see the ticks or the axis labels, you can set them to transparent.)

(b) There may be another line in your code that disables the grid lines. (Apparently your code in the message is only part of the charting code.)


If you need further help, is it possible to attach a chart image so I can see what you get so far, and also more complete charting code, so I can help to check if there is another line of code that disables the grids.

Regards
Peter Kwan

  Re: hello
Posted by shila on Jan-08-2009 21:33
Hello

Can you tell me where we can mention how many gridlines are shown.
Like i have one combox in toolbar
with choices 5 ,7 ,9.
so if user selects 5 it should show 5 gridlines.

And also tell me how we can the distance on y axis.

im attaching the bmp file.
so in that on vertical axis we hav


500
250
125
0

how this is set
means the distance betwee two values is 125..

how its done
reply asap...

Thanks
Shila

  Re: hello
Posted by Peter Kwan on Jan-09-2009 02:37
Hi Shila,

For some reasons, I cannot see your BMP file. Note that the forum software only support files up to 250 Kbytes. If your BMP file is larger, you may need to zip it first. Also, you may need to press the "Send File" button to send the file.

For the grid lines and axis labels, if you want to have the grid lines and axis labels at 0, 125, 250, 375, 500, the code is:

c->yAxis()->setLinearScale(0, 500, 125);

The above will have 5 grid lines (if you count the grid lines at 0 and 500 as well), at 0, 125, 250, 375, 500. In general, for N grid lines, the code is:

c->yAxis()->setLinearScale(0, 500, 500 / (N - 1));

Note that if you choose a number such that 500 is not divisble by (N - 1), the axis labels may contain decimals.

Hope this can help.

Regards
Peter Kwan

  Re: hello
Posted by shila on Jan-09-2009 12:44
Attachments:
Hello,

Below is whole code

   // Create an XYChart object with the same background color
// as the container
        XYChart *c = new XYChart(iCX, iCY);

if(m_IsGridOn == TRUE)
{
// Set the plotarea
c->setPlotArea(m_Rect.left,                 // x40
   m_Rect.top,                  // y80
   m_Rect.right - m_Rect.left,  // width
   m_Rect.bottom - m_Rect.top,  // height
   -1,                          // bgColor
   -1,                          // altBgColor
   Chart::Transparent,          // edgeColor
   c->dashLineColor(0xcccccc, Chart::DashLine),  // hGridColor
   c->dashLineColor(0xcccccc, Chart::DashLine)); // vGridColor
}
else
{
c->setPlotArea(m_Rect.left,                 // x40
   m_Rect.top,                  // y80
   m_Rect.right - m_Rect.left,  // width
   m_Rect.bottom - m_Rect.top,  // height
   -1,                          // bgColor
   -1,                          // altBgColor
   Chart::Transparent,          // edgeColor
   0xffffff);                   // hGridColor
}

        // Enable clipping mode to clip the part of the data that is outside the plot area.
        c->setClipping();

        // Drawing a grid line on top edge of the y axis.
        c->addLine( m_Rect.left - 8, m_Rect.top,
            m_Rect.left - 3, m_Rect.top ,0xFFFF0001, 1);
        c->addLine( m_Rect.left + 3, m_Rect.top,
            m_Rect.left + 8, m_Rect.top ,0xFFFF0001, 1);

        // Add a titles to axes
        c->xAxis()->setTitle(" ");
        c->yAxis()->setTitle(" ");

        LineLayer *layer = NULL;

        CDC *pDC = GetDC();
        CString sYMax(_T(""));
        CString sYMin(_T(""));
        SIZE Size = {0,};
        BOOL bResult = FALSE;
        HDC hDC = pDC->GetSafeHdc();
        INT iMaxX = 0;
        INT iMaxY = 0;

        INT iMinX = 0;
        INT iMinY = 0;

CFont *pOldFont = NULL;
if( m_pFont != NULL )
pOldFont = pDC->SelectObject(m_pFont);

        // Add a line layer to for the second data set using green (00c0000) color, with
        // a line width of 2 pixels. Bind the layer to the secondary y-axis.
        CString sSignalName(_T(""));

        if (NULL == m_pdMinY)
        {
            m_pdMinY = new DOUBLE[ID_SIGNAL_COUNT];
        }

        if (NULL == m_pdMaxY)
        {
            m_pdMaxY = new DOUBLE[ID_SIGNAL_COUNT];
        }

if (NULL == m_dMinYZoom)
{
m_dMinYZoom = new DOUBLE[ID_SIGNAL_COUNT];
}

if (NULL == m_dMaxYZoom)
{
m_dMaxYZoom = new DOUBLE[ID_SIGNAL_COUNT];
}

        Axis *leftAxis[ID_SIGNAL_COUNT];
        for(INT i = 0; i < wNoOfLoggedSignals; i++)
        {
            if (FALSE == bReadCheckSignals || arrChkdSignals[i] == 1)
            {
                // Add the y-axis to the left of the plot area
                leftAxis[i] = c->addAxis(Chart::Left, (50 /*- (i * 20)*/));
                // Set the axis, with trasparent color
                leftAxis[i]->setColors(0xffffff, 0xffffff);
            }
        }

         //////////Data for HighLighted Line////////////////
        INT iHighLightIndex = -1;
        BOOL bIsHighLight = FALSE;
        DWORD dwHighLightColor =0;
        CString sSignal(_T(""));
        if(NULL != pLegend)
        {
            bIsHighLight = pLegend->IsHighLight();
            if(bIsHighLight)
            {
                iHighLightIndex = pLegend->GetHighLightSignalIndex();
            }
        }


DoubleArray arrYData;
        if(0 >= aLoggedSignalNames.GetSize() || 0 >= aSignalColors.GetSize())
        {
            return;
        }

        /////Draw lines
        for (i = 0; i < wNoOfLoggedSignals; i++)
        {
            if (FALSE == bReadCheckSignals || arrChkdSignals[i] == 1)
            {
                sSignalName = aLoggedSignalNames.GetAt(i);
#ifdef _UNICODE
                LPWSTR wszSignalsName = sSignalName.GetBuffer(0);
                CHAR *szSignalsName = new CHAR[wcslen(wszSignalsName) + 1];
                wcstombs(szSignalsName, wszSignalsName, wcslen(wszSignalsName));
                szSignalsName[wcslen(wszSignalsName)] = '\\0';
#else
                CHAR *szSignalsName = sSignalName.GetBuffer(0);
#endif

                COLORREF colref = aSignalColors.GetAt(i);
                DWORD dwColor = (colref & 0x000000FF) << 16
                    | (colref & 0x0000FF00)
                    | (colref & 0x00FF0000) >> 16;

// DJ: Fix for S. No. 157
                // We copy the visible data from the main arrays to separate data arrays
pYData[i] = new double[noOfPoints];

memcpy(pYData[i], ppdSignalValues[i] + startIndex, arraySizeInBytes);

lYDataLen = noOfPoints;

arrYData = DoubleArray (pYData[i], lYDataLen);

                memcpy(pXData, pdSignalTimeLevels + startIndex, arraySizeInBytes);

                lXDataLen = noOfPoints;

                arrXData = DoubleArray (pXData, lXDataLen);

                if(iHighLightIndex == i)
                {
                    dwHighLightColor = dwColor;
                    sSignal = sSignalName;
#ifdef _UNICODE
if (NULL != szSignalsName)
{
delete []szSignalsName;
szSignalsName = NULL;
}
#endif
                    continue;
                }

FLOAT fScaleVal = 1.0;

if(aLoggedSignals.GetSize() > i)
{
Signal LoggedSignal = aLoggedSignals.GetAt(i);
if(E_SOLUTION_SIGNAL == LoggedSignal.wSignalType)
{
E_SEL_DISP_FORMAT eDisplayFormat;
pInfo = (LoggerSignalInfo *)aParamList.GetAt(i);

if(NULL != pInfo)
{
if(pInfo->eSignalSourceType == E_SOLUTION_SIGNAL)
{
pSignal = (CSMSolutionSignal *)pInfo->pSolutionSignal;
if(NULL != pSignal)
{
eDisplayFormat = pSignal->GetLoggerSelDisplayFormat();
if(eDisplayFormat == E_DISPLAYFORMAT_DEFAULT_FLOAT)
{
pSignal->GetScaleValue(fScaleVal);
}
}
}
}
}

if( fScaleVal != (DOUBLE)1.0 )
{
ArrayMath aMath = ArrayMath(arrYData);
DoubleArray arrYData1 = aMath.mul(fScaleVal);

memcpy( pYData[i], arrYData1.data, arraySizeInBytes);

arrYData = DoubleArray (pYData[i], lYDataLen);
}
}

                layer = c->addLineLayer(arrYData, dwColor, szSignalsName);

layer = c->addLineLayer(arrXData,10);
                layer->setXData(arrXData);

                layer->setLineWidth(1);
                layer->setUseYAxis(leftAxis[i]);

layer->setGapColor(Transparent);
#ifdef _UNICODE
                if (NULL != szSignalsName)
                {
                    delete []szSignalsName;
                    szSignalsName = NULL;
                }
#endif
                sSignalName.ReleaseBuffer();
            }
        }

        ///draw Highlighted line
        if(bIsHighLight)
        {
            if(arrChkdSignals[iHighLightIndex] == 1 && iHighLightIndex <= wNoOfLoggedSignals - 1)
            {
#ifdef _UNICODE
                LPWSTR wszSignalsName = sSignal.GetBuffer(0);
                CHAR *szSignalsName = new CHAR[wcslen(wszSignalsName) + 1];
                wcstombs(szSignalsName, wszSignalsName, wcslen(wszSignalsName));
                szSignalsName[wcslen(wszSignalsName)] = '\\0';
#else
                CHAR *szSignalsName = sSignal.GetBuffer(0);
#endif

FLOAT fScaleVal = 1.0;

Signal LoggedSignal = aLoggedSignals.GetAt(iHighLightIndex);
if(E_SOLUTION_SIGNAL == LoggedSignal.wSignalType)
{
E_SEL_DISP_FORMAT eDisplayFormat;
pInfo = (LoggerSignalInfo *)aParamList.GetAt(iHighLightIndex);

if(NULL != pInfo)
{
if(pInfo->eSignalSourceType == E_SOLUTION_SIGNAL)
{
pSignal = (CSMSolutionSignal *)pInfo->pSolutionSignal;
if(NULL != pSignal)
{
eDisplayFormat = pSignal->GetLoggerSelDisplayFormat();
if(eDisplayFormat == E_DISPLAYFORMAT_DEFAULT_FLOAT)
{
pSignal->GetScaleValue(fScaleVal);
}
}
}
}
}

arrYData = DoubleArray(pYData[iHighLightIndex], lYDataLen);
if( fScaleVal != (DOUBLE)1.0 )
{
ArrayMath aMath = ArrayMath(arrYData);
DoubleArray arrYData1 = aMath.mul(fScaleVal);

memcpy( pYData[iHighLightIndex], arrYData1.data, arraySizeInBytes);

arrYData = DoubleArray (pYData[iHighLightIndex], lYDataLen);
}

                layer = c->addLineLayer(arrYData, dwHighLightColor, szSignalsName);

                layer->setXData(arrXData);

                layer->setLineWidth(2);
                layer->setUseYAxis(leftAxis[iHighLightIndex]);

layer->setGapColor(Transparent);

                /// Draw Y=0 Dash line
                if (m_pdDashAxis == NULL)
                {
                    m_pdDashAxis = new DOUBLE[lYDataLen];
                }
                else
                {
                    delete m_pdDashAxis;
                    m_pdDashAxis = new DOUBLE[lYDataLen];
                }

                for(INT j = 0 ; j< lYDataLen; j++)
                {
                    m_pdDashAxis[j] = 0.0;
                }

               layer = c->addLineLayer(DoubleArray(m_pdDashAxis, lYDataLen),
                    c->dashLineColor(dwHighLightColor, Chart::DashLine),
                    szSignalsName);

                layer->setXData(arrXData);

                layer->setLineWidth(1);
                layer->setUseYAxis(leftAxis[iHighLightIndex]);

layer->setGapColor(Transparent);
#ifdef _UNICODE
                if (NULL != szSignalsName)
                {
                    delete []szSignalsName;
                    szSignalsName = NULL;
                }
#endif
                sSignal.ReleaseBuffer();
            }
        }

        ///////////////////////////////////////////////
        //make axis as dash line
        c->yAxis()->setColors(c->dashLineColor(0x000000, Chart::DashLine));
        c->xAxis()->setColors(c->dashLineColor(0x000000, Chart::DashLine));

        ///////////////////////////////////////////////////////////////
        if (m_maxX == m_minX)
        {
            // Save the axis scales for future use
            m_minX = pdSignalTimeLevels[0];
            m_maxX = pdSignalTimeLevels[dwNoOfSampleSets-1];
            m_minY = c->yAxis()->getMinValue();
            m_maxY = c->yAxis()->getMaxValue();

// Store Min and max axis values.
// [10/14/2007] - DJ: Modified fix for S. No. 79 (Original Scale)
m_dblEditMinX = m_minX + (m_maxX - m_minX) * m_ChartViewer.getViewPortLeft();
m_dblEditMaxX = m_minX + (m_maxX - m_minX) * (m_ChartViewer.getViewPortLeft() +
m_ChartViewer.getViewPortWidth());

            for (i = 0; i < wNoOfLoggedSignals; i++)
            {
// DJ: first time read min and max values of all the signals
                if (FALSE == bReadCheckSignals /*|| arrChkdSignals[i] == 1*/)
                {
if(  eOpenDocMode != E_OPEN_DSM && eOpenDocMode != E_OPEN_DSL )
{
m_pdMinY[i] = dYScaleMin[i];
m_pdMaxY[i] = dYScaleMax[i];

m_dMinYZoom[i] = m_pdMinY[i];
m_dMaxYZoom[i] = m_pdMaxY[i];
}
else
{
// For dsm and dsl files, we are reading min/max values from file and setting them.
// Use the same values when file is opened for the first time.
dYScaleMin[i]   = m_pdMinY[i];
dYScaleMax[i]   = m_pdMaxY[i];

m_dMinYZoom[i] = m_pdMinY[i];
m_dMaxYZoom[i] = m_pdMaxY[i];
}

}
            }
        }
        else
        {
if( m_bFlag )
{
m_prevMinX = m_minX;
m_prevMaxX = m_maxX;
m_bFlag = FALSE;
}
        }

// Calculate x-axis values
        xScaleMin = m_minX + (m_maxX - m_minX) * m_ChartViewer.getViewPortLeft();
        xScaleMax = m_minX + (m_maxX - m_minX) * (m_ChartViewer.getViewPortLeft() +
            m_ChartViewer.getViewPortWidth());

        // Set the axis scales
        c->xAxis()->setLinearScale(xScaleMin, xScaleMax);
        c->xAxis()->setRounding(true, true);

        //set values for each Y axis
        for (i = 0; i < wNoOfLoggedSignals; i++)
        {
            if (FALSE == bReadCheckSignals || arrChkdSignals[i] == 1)
            {
                leftAxis[i]->setLinearScale(dYScaleMin[i], dYScaleMax[i],dYScaleMax[i],dYScaleMax[i]/(5-1));
                leftAxis[i]->setRounding(true, true);
            }
        }
this.rar
this.rar

18.72 Kb

  Re: hello
Posted by Peter Kwan on Jan-09-2009 17:57
Hi shila,

I assume the question is to ask why the chart has no grid lines.

ChartDirector can support arbitrary large number of y-axes. For example, you can have 100 y-axes on the chart. To draw grid lines, ChartDirector will use the ticks on the "primary y-axis" (the c->yAxis()).  (ChartDirector cannot draw grid lines using all the ticks in all the y-axes, otherwise the chart will be unreadable.)

In your case, you are using multiple y-axes. However, the primary y-axis is never used.

To solve the problem, please make sure one of the y-axis you use is the primary y-axis. For example:


bool isFirstAxis = true;
Axis *leftAxis[ID_SIGNAL_COUNT];
for(INT i = 0; i < wNoOfLoggedSignals; i++)
{
    if (FALSE == bReadCheckSignals || arrChkdSignals[i] == 1)
    {
          if (isFirstAxis)
          {
               leftAxis[i] = c->yAxis();
               isFirstAxis = false;
          }
          else
          {
                // Add the y-axis to the left of the plot area
                leftAxis[i] = c->addAxis(Chart::Left, (50 /*- (i * 20)*/));
                // Set the axis, with trasparent color
                leftAxis[i]->setColors(0xffffff, 0xffffff);
          }
     }
}


Also, you are configuring your axis with no major ticks, and also the tick increment computation in setLinearScale is incorrect. I am not sure if this is intentional. If you want to see the labels on the axis, you need to use major ticks. The code should be:

leftAxis[i]->setLinearScale(dYScaleMin[i], dYScaleMax[i], (dYScaleMax[i] - dYScaleMin[i]) / (5 - 1));

(Note: I have never tried to run your code. So my suggested code may or may not work. You may need to trouble-shoot it.)

Hope this can help.

Regards
Peter Kwan