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

Message ListMessage List     Post MessagePost Message

  setXData function.. help me
Posted by anna on Mar-17-2014 08:06
CParamDlg.h

public:
double *ydata1 ; // hjyun 0314
double *ydataindex1 ; // hjyun 0314


void CParamDlg::UpdateHisto()
{
      double* xProjData = new double[Length+1]; //<============ ?
      double* yProjData = new double[Length+1]; //<============ ?

//<======== declaration type  ///////double* ///////
// how to coding?
// double xProjData[] = {1,2,3,4,5,6,7,8,9,10} is good well. How to convert?




for (long index = 0; index < Length; index ++)
{
       xProjData[index] = index + 1;
       yProjData[index] = (double)pProjection[index];
}

    drawChart(&m_ChartViewer);

}


void CParamDlg::drawChart(CChartViewer *viewer)
{
     XYChart *c = new XYChart(392, 100);

     c->setPlotArea(35, 30 , c->getWidth()-50, c->getHeight()-50, c->linearGradientColor(35, 30, 0,  c->getHeight()-50, 0xf0f6ff, 0xa0c0ff), -1, Chart::Transparent, 0xffffff, 0xffffff);


     c->xAxis()->setLabelStyle("arialbd.ttf", 8);
     c->yAxis()->setLabelStyle("arialbd.ttf", 8);

     c->xAxis()->setColors(Chart::Transparent);
     c->yAxis()->setColors(Chart::Transparent);


     LineLayer *layer = c->addLineLayer();
     layer->setLineWidth(2);

     layer->setXData(DoubleArray(xProjData , (int)(sizeof(xProjData ) / sizeof(xProjData [0])))); ///<============== error "xProjData" <=========== ??????

     layer->addDataSet(DoubleArray(yProjData, (int)(sizeof(yProjData) / sizeof(yProjData[0]))), 0xcc0000, "Power");
//<=================== error "yProjData" <=========== ??????

     viewer->setChart(c);
}




Help me..

  Re: setXData function.. help me
Posted by Peter Kwan on Mar-18-2014 00:58
Hi anna,

There are 3 errors in the code:

(a) xProjData and yProjData are declared as local variables in your code, so they do not
exist outside UpdateHisto and therefore cannot be used in drawChart. Please declare
them as member variables or global variables instead.

(b) In C++, the array index starts from 0. If you start from 1, then the first element at
index 0 is not initialize and become a random number. So the chart would be incorrect.
The correct code is:

CParamDlg.h

public:
double *xProjData;
double *yProjData;

....

void CParamDlg::UpdateHisto()
{
     xProjData = new double[Length];
     yProjData = new double[Length];

     for (long index = 0; index < Length; index ++)
    {
         xProjData[index] = index + 1;
         yProjData[index] = (double)pProjection[index];
    }

    drawChart(&m_ChartViewer);
}

(c) The length of the array is Length, not  "(int)(sizeof(xProjData ) / sizeof(xProjData
[0]))";. Using sizeof to determine array size is valid for array with a declared size. Your
xProjData and yProjData are not declared as arrays, but as pointers to double, so the
sizeof method is not applicable. In your code, the size is already in the Length variable,
you can directly use the Length variable as the length (eg. DoubleArray(xProjData,
Length)).

Hope this can help.

Regards
Peter Kwan