• 16799阅读
  • 8回复

[提问]qcustomplot 怎么更改横轴为时间轴 [复制链接]

上一主题 下一主题
离线15927174837
 

只看楼主 倒序阅读 楼主  发表于: 2016-05-10
回复本帖可获得3RMB金钱奖励!
每人最多可获奖1次,奖池剩余9RMB金钱 (中奖几率20%)
要可配置的更改,可切换时间轴和数值轴
离线15927174837

只看该作者 1楼 发表于: 2016-05-10
求大神帮助啊
离线xiaoniede

只看该作者 2楼 发表于: 2016-05-10
///设置数值类型的坐标轴
    ui->customplot->xAxis->setTickLabelType(QCPAxis::ltNumber);
    ui->customplot->xAxis->setNumberFormat("fb");
    ui->customplot->xAxis->setNumberPrecision(0);///小数点位数
    ui->customplot->xAxis->setRange(0,1000);

    ui->customplot->replot();
///设置时间类型的坐标轴
    double dCurSeconds = QDateTime::currentDateTimeUtc().toTime_t();
    double dRangeLower = dCurSeconds-3600;
    double dRangeHight = dCurSeconds;

    ui->customplot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->customplot->xAxis->setRange(dRangeLower, dRangeHight);
    ui->customplot->xAxis->setDateTimeFormat("hh:mm");
    ui->customplot->xAxis->setDateTimeSpec(Qt::UTC);

    ui->customplot->replot();

以上为实例代码,你可以试一下。
离线15927174837

只看该作者 3楼 发表于: 2016-05-10
回 xiaoniede 的帖子
xiaoniede:///设置数值类型的坐标轴
    ui->customplot->xAxis->setTickLabelType(QCPAxis::ltNumber);
    ui->customplot->xAxis->setNumberFormat("fb");
    ui->customplot->xAxis-&g .. (2016-05-10 21:54) 

这个不能切换啊,比如说原来是这个类型:QCPAxis::ltNumber,就不能切换到QCPAxis::ltDateTime?2个不能相互切换啊
离线xiaoniede

只看该作者 4楼 发表于: 2016-05-11
可以!再次设置之后要 ui->customplot->replot(); 。
离线15927174837

只看该作者 5楼 发表于: 2016-05-12
回 xiaoniede 的帖子
xiaoniede:可以!再次设置之后要 ui->customplot->replot(); 。 (2016-05-11 10:08) 

这个用了,但是没用啊!!!
所以现在我将x轴label用时间换成相应的qstring了!!

你画过柱状图没有,为什么有些柱子不能显示啊
离线15927174837

只看该作者 6楼 发表于: 2016-05-12

这是为什么啊
本帖提到的人: @xiaoniede
离线xiaoniede

只看该作者 7楼 发表于: 2016-05-18
出差啦,没有及时回复。肯定可以的。
离线misgn

只看该作者 8楼 发表于: 2016-08-09
  yAxis->setTickLabelType(QCPAxis::ltDateTime);//设置轴刻度的显示类型,一种为数字,一种为时间。设置后可以设置数据显示的格式化。

http://blog.csdn.net/u012365926/article/details/52121791
快速回复
限100 字节
 
上一个 下一个