|
step line chart zoom in/out and scroll |
Posted by jungryul kim on Feb-19-2024 11:54 |
|
I am trying to add a zoom function to the step line chart.
The x-axis of each line has CTime data and the y-axis values are 0 to 7.
The range of the x-axis may be different for each line and the quantity may also be different.
The output results are drawn as a step line chart as follows.
The x-axis displays the CTiem format in seconds, such as '2024-02-01 02:22:33'.
When trying to add zoom in/out function, it is difficult to implement in the code below.
///////////////////////////////////////////////////// ///////////////
void CSimpleZoomScrollDlg::initChartViewer(CChartViewer *viewer)
{
viewer->setFullRange("x", m_timeStamps[0], m_timeStamps[m_timeStamps.len - 1]);
viewer->setViewPortWidth(0.2);
viewer->setViewPortLeft(1 - viewer->getViewPortWidth());
viewer->setZoomInWidthLimit(10.0 / m_timeStamps.len);
viewer->setMouseWheelZoomRatio(1.1);
m_PointerPB.SetCheck(1);
viewer->setMouseUsage(Chart::MouseUsageScroll);
}
///////////////////////////////////////////////////// ///////////////////
Sample data is generated as follows:
m_timeStamps = m_ranSeries->getDateSeries(1827, Chart::chartTime(2007, 1, 1), 86400);
m_dataSeriesA = m_ranSeries->getSeries(1827, 150, -10, 10);
m_dataSeriesB = m_ranSeries->getSeries(1827, 200, -10, 10);
m_dataSeriesC = m_ranSeries->getSeries(1827, 250, -8, 8);
You can zoom only if the number of x-axis data and the actual data are the same.
In reality, the data I have has different numbers and x-axis ranges for each line, so I don't know how to apply the above example.
I would like to inquire.
|
Re: step line chart zoom in/out and scroll |
Posted by jungryul kim on Feb-19-2024 13:19 |
|
Below are the database search results and step line chart code.
A layer is assigned to each line, and the x-axis range is also assigned separately.
|
Re: step line chart zoom in/out and scroll |
Posted by Peter Kwan on Feb-19-2024 17:09 |
|
Hi Jungryul Kim
The chart can work even if the x data range for the lines are different. You just need to modify the code to determine the viewPortTimeStamps and viewPortDataSeries separately. Also, you need to compute the full x-axis range by considering all the x data series.
In the original code, there is a line to configure the x-axis range:
viewer->setFullRange("x", m_timeStamps[0], m_timeStamps[m_timeStamps.len - 1]);
Even though you have multiple x data series, the entire chart still contains only one x-axis at the bottom of the plot area. The min and max values should be:
// Get the min/max x value by considered all x data series
double minX = m_pChartX[0][0];
double maxX = m_pChartX[0][m_nChartYSize[0] - 1];
for (int i = 1; i < m_nLineSize; ++i) {
minX = std::min(minX, m_pChartX[i][0]);
maxX = std::max(maxX, m_pChartX[i][m_nChartYSize[i] - 1]);
}
// This is the full range
viewer->setFullRange("x", minX, maxX);
Then in the charting code, in the original sample code, the viewPortTimeStamps are determined using:
// 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);
Because you have multiple x data series, you need to change it to a loop like:
std::vector<DoubleArray> viewPortTimeSeries;
std::vector<DoubleArray> viewPortDataSeries;
for (int i = 0; i < m_nLineSize; i++)
{
DoubleArray dataX(m_pChartX[i], m_nChartYSize[i]);
DoubleArray dataY(m_pChartY[i], m_nChartYSize[i]);
// Get the array indexes that corresponds to the visible start and end dates
int startIndex = (int)floor(Chart::bSearch(dataX, viewPortStartDate));
int endIndex = (int)ceil(Chart::bSearch(dataX, viewPortEndDate));
int noOfPoints = endIndex - startIndex + 1;
// Extract the part of the data array that are visible.
viewPortTimeSeries.push_back(DoubleArray(dataX.data + startIndex, noOfPoints));
viewPortDataSeries.push_back(DoubleArray(dataY.data + startIndex, noOfPoints));
}
Then you can add the layers using:
You need to change it to a loop:
for (int i = 0; i < m_nLineSize; i++)
{
layer[i] = c->addStepLineLayer();
layer[i]->addDataSet(viewPortDataSeries[i]);
layer[i]->setXData(viewPortTimeSeries[i]);
layer[i]->setLineWidth(2);
}
Best Regards
Peter Kwan |
Re: step line chart zoom in/out and scroll |
Posted by jungryul kim on Feb-20-2024 10:06 |
|
The problem was resolved by applying the code you provided.
I learned how to zoom in/out scroll sufficiently even for unevenly shaped lines.
Thank you very much.
|
|