|
i have a question |
Posted by seoyyung on Jan-22-2022 23:39 |
|
i have a bug of this viewport control chart.
When it is first drawn, it is drawn well, but when you update the screen, it looks like this.
what should i do?
https://www.twitch.tv/videos/1271143826
win10
c++17
qt newest version
chartdirector 7.0
my code is following viewportcontroldemo.cpp and .h
changed chart size only |
Re: i have a question |
Posted by Peter Kwan on Jan-23-2022 13:34 |
|
I suspect it is due to corrupted data arrays.
When you move the viewport, the code should call “drawChart” to redraw the chart again. The code in the “drawChart” will get the visible data based on the viewport position. In the sample code, it is like:
// Get the start date and end date that are visible on the chart.
double viewPortStartDate = viewer->getValueAtViewPort("x", viewer->getViewPortLeft());
double viewPortEndDate = viewer->getValueAtViewPort("x", viewer->getViewPortLeft() +
viewer->getViewPortWidth());
// Get the array indexes that corresponds to the visible start and end dates
int startIndex = (int)floor(Chart::bSearch(m_timeStamps, viewPortStartDate));
int endIndex = (int)ceil(Chart::bSearch(m_timeStamps, viewPortEndDate));
int noOfPoints = endIndex - startIndex + 1;
// Extract the part of the data array that are visible.
DoubleArray viewPortTimeStamps = DoubleArray(m_timeStamps.data + startIndex, noOfPoints);
DoubleArray viewPortDataSeriesA = DoubleArray(m_dataSeriesA.data + startIndex, noOfPoints);
DoubleArray viewPortDataSeriesB = DoubleArray(m_dataSeriesB.data + startIndex, noOfPoints);
DoubleArray viewPortDataSeriesC = DoubleArray(m_dataSeriesC.data + startIndex, noOfPoints);
Please make sure all the data arrays are valid. For example, if you deleted the data after plotting the first chart, then the data becomes invalid. When you drag the viewport to redraw the chart, it will obtain incorrect or random data, and so the chart becomes unpredictable.
For Qt, you can use qDebug to print out some the data values to the debugger window. For example:
qDebug("startIndex = %d, endIndex = %d, startValue = %f, endValue = %fn", startIndex, endIndex, m_dataSeriesA.data[startIndex], m_dataSeriesA.data[endIndex - 1]);
Now when your drag the viewport, you can see the startIndex as well as the data value at the stateIndex. If the startIndex looks reasonable, but the data value looks unreasonable (eg. you obtain a value like 289374017402). then it means the m_dataSeriesA.data contains incorrect data. In this case, please check why the data array becomes corrupted.
Regards
Peter Kwan |
Re: i have a question |
Posted by seoyyung on Jan-24-2022 22:29 |
|
qDebug output data is
startIndex = 733, endIndex = 846, startValue = 0.000000, endValue = 0.000000n
startIndex = 733, endIndex = 846, startValue = 0.000000, endValue = 0.000000n
startIndex = 733, endIndex = 845, startValue = 0.000000, endValue = 0.000000n
startIndex = 732, endIndex = 845, startValue = 120.000000, endValue = 0.000000n
startIndex = 732, endIndex = 845, startValue = 120.000000, endValue = 0.000000n
startIndex = 730, endIndex = 844, startValue = 1722.000000, endValue = 0.000000n
startIndex = 726, endIndex = 840, startValue = 120.000000, endValue = 0.000000n
startIndex = 725, endIndex = 840, startValue = 120.000000, endValue = 0.000000n
startIndex = 724, endIndex = 838, startValue = 1722.000000, endValue = 0.000000n
startIndex = 723, endIndex = 837, startValue = 0.000000, endValue = 0.000000n
startIndex = 721, endIndex = 836, startValue = 0.000000, endValue = 0.000000n
i tried data arrays changed into struct.
but do not changed result.
my source code is
https://github.com/sy-project/FITIVersion |
Re: i have a question |
Posted by Peter Kwan on Jan-25-2022 05:16 |
|
Hi seoyyung,
The DoubleArray only stores a pointer to the data array. It does not make a copy of the data.
In your code, the data arrays are allocated using:
double AmbientTemperature[tempv.size()];
double AmbientHumidity[tempv.size()];
double TargetTemperature[tempv.size()];
double TargetHumidity[tempv.size()];
double LampPreset[tempv.size()];
double DO1[tempv.size()];
double DO2[tempv.size()];
double DO3[tempv.size()];
double DO4[tempv.size()];
double DO5[tempv.size()];
double Time[tempv.size()];
However, the above are local variables inside the on_btSearch_clicked method. When your code returns from on_btSearch_clicked, the local variables are destroyed. So the pointers in DoubleArray are no longer valid.
To solve the problem, please allocate the data arrays in the SearchScene object. For example, in the header file, you can add:
std::vector<double> AmbientTemperature;
std::vector<double> TargetTemperature;
std::vector<double> TargetHumidity;
......
......
std::vector<double> Time;
In this way, the data arrays will have the same lifetime as the SearchScene object.
In on_btSearch_clicked, instead of:
double AmbientTemperature[tempv.size()];
please change it to:
AmbientTemperature.resize[tempv.size()];
Also, please change:
m_dtArr.AmbTemp = DoubleArray(AmbientTemperature, tempv.size());
to:
m_dtArr.AmbTemp = DoubleArray(&(AmbientTemperature[0]), AmbientTemperature.size());
Hope this can help.
Regards
Peter Kwan |
Re: i have a question |
Posted by seoyyung on Jan-25-2022 07:17 |
|
oh thanks.
its solved!
i think I just need to declare only DoubleArray variables in the header when i written that code. |
|