[英]Qt - Scrolling the visible area of the chart
I'm beginner at Qt, and currently learning from Mastering Qt5 book and I got stuck. 我是Qt的初学者,目前正在学习精通Qt5书籍,但遇到了麻烦。 There is a piece of code 有一段代码
// Global variables
const int CHART_X_RANGE_COUNT = 50;
const int CHART_X_RANGE_MAX = CHART_X_RANGE_COUNT - 1;
void MemoryWidget::updateSeries()
{
double memoryUsed = SysInfo::instance().memoryUsed(); // retrieve the latest memory percentage used
mSeries->append(mPointPositionX++, memoryUsed);
if (mSeries->count() > CHART_X_RANGE_COUNT)
{
QChart *chart = chartView().chart();
chart->scroll(chart->plotArea().width() / CHART_X_RANGE_MAX, 0);
mSeries->remove(0);
}
}
I only don't understand the following piece of code 我只是不明白下面的代码
chart->scroll(chart->plotArea().width() / CHART_X_RANGE_MAX, 0);
If I want to scroll to the latest point on the X axis and nothing on Y, then why i have to do this: 如果我想滚动到X轴上的最新点,而不是Y轴上的任何东西,那么为什么我必须这样做:
chart->plotArea().width() / CHART_X_RANGE_MAX
and can't do just this: 并且不能做到这一点:
chart->scroll(1, 0);
According to docs scroll
Scrolls the visible area of the chart by the distance specified by dx and dy. 根据docs scroll
滚动图表的可见区域dx和dy指定的距离。
and why chart->scroll(chart->plotArea().width() / CHART_X_RANGE_MAX, 0);
以及为什么chart->scroll(chart->plotArea().width() / CHART_X_RANGE_MAX, 0);
because mSeries->append(mPointPositionX++, memoryUsed);
因为mSeries->append(mPointPositionX++, memoryUsed);
is called periodically and after a while a full window of xaxis will be filled and after each full window fills plot will scroll, if you use chart->scroll(1, 0);
如果您使用chart->scroll(1, 0);
,则将定期调用此函数,并在一段时间后将填充xaxis的整个窗口,并且在每个完整窗口填充之后,图将滚动chart->scroll(1, 0);
each time updateSeries()
called you scroll window to next and always showing last point, 每当updateSeries()
调用您将窗口滚动到下一个并始终显示最后一个点时,
In general this plot wants to scroll per CHART_X_RANGE_MAX
. 通常,此图CHART_X_RANGE_MAX
滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.