|
setXData |
Posted by anna on Mar-16-2014 20:34 |
|
void CParamDlg::UpdateHisto()
{
double* xProjData = new double[Length+1]; //<============ ?
double* yProjData = new double[Length+1]; //<============ ?
//<======== declaration type ///////double* ///////
for (long index = 1; index < Length+1; index ++)
{
xProjData[index] = index;
yProjData[index] = (double)pProjection[index-1];
}
drawChart(&m_ChartViewer);
}
// Draw the chart and display it in the given viewer
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);
} |
how to do? help me. i dont know |
Posted by anna on Mar-16-2014 21:00 |
|
Help me
I dont konw. |
Re: how to do? help me. i dont know |
Posted by Peter Kwan on Mar-16-2014 23:39 |
|
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:
void CParamDlg::UpdateHisto()
{
xProjData = new double[Length]; //<============ ?
yProjData = new double[Length]; //<============ ?
//<======== declaration type ///////double* ///////
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.
Hope this can help.
Regards
Peter Kwan |
|