Qt-QCustomPlot(画坐标系统)的简单操作

一、QCustomPlot的简单配置

 1    /* 清除所有曲线 */
 2     ui->curve->clearGraphs();
 3     /* 设置背景色 */
 4     ui->curve->setBackground(QBrush(QColor(255,255,255,0)));
 5 
 6     #if 0
 7     /* 设置右上角图标可见 */
 8     ui->curve->legend->setVisible(true);
 9     /* 设置右上角图标字体 */
10     ui->curve->legend->setFont(QFont("Helvetica", 9));
11     /* 设置右上角图标背景色 */
12     ui->curve->legend->setBrush(QColor(255,255,255,0));
13     #endif
14     /* 设置坐标轴标题 */
15     ui->curve->xAxis->setLabel("时间(min)");
16     ui->curve->xAxis->setLabelFont(QFont("Ubuntu",12));
17     ui->curve->yAxis->setLabel("温度(℃)");
18     ui->curve->yAxis->setLabelFont(QFont("Ubuntu",12));
19 
20     /* 设置坐标轴标题颜色 */
21     ui->curve->xAxis->setLabelColor(Qt::white);
22     ui->curve->yAxis->setLabelColor(Qt::white);
23     /* 设置坐标轴数字颜色 */
24     ui->curve->xAxis->setTickLabelColor(Qt::white);
25     ui->curve->yAxis->setTickLabelColor(Qt::white);
26     /* 设置坐标轴颜色和线粗 */
27     ui->curve->xAxis->setBasePen(QPen(QColor(255,128,4), 2));
28     ui->curve->yAxis->setBasePen(QPen(QColor(255,128,4), 2));
29 
30     /* 设置坐标轴范围 */
31     QSharedPointer timeTicker(new QCPAxisTickerTime);
32     timeTicker->setTimeFormat("%m");
33     ui->curve->xAxis->setTicker(timeTicker);
34     /* 设置x轴范围是1-3601s,即60分钟 */
35     ui->curve->xAxis->setRange(1, 3600);
36     /* 设置x轴分割线向外和分割线高度 */
37     ui->curve->xAxis->setTickLength(0, 5);
38     ui->curve->xAxis->setSubTickLength(0, 3);
39     /* 设置x轴分割线的颜色和线粗 */
40     ui->curve->xAxis->setTickPen(QPen(QColor(255,128,4),2));
41     ui->curve->xAxis->setSubTickPen(QPen(QColor(255,128,4),2));
42 
43     /* 设置y轴范围 */
44     ui->curve->yAxis->setRange(0, 400);
45     /* 设置x轴分割线向外和分割线高度 */
46     ui->curve->yAxis->setTickLength(0, 5);
47     ui->curve->yAxis->setSubTickLength(0, 0);
48     /* 设置y轴分割线的颜色和线粗 */
49     ui->curve->yAxis->setTickPen(QPen(QColor(255,128,4),2));
50     ui->curve->yAxis->setSubTickPen(QPen(QColor(255,128,4),2));
51 
52     /* 设置网格线的颜色为透明 */
53     ui->curve->xAxis->grid()->setPen(QPen(QColor(255,255,255,0)));
54     ui->curve->yAxis->grid()->setPen(QPen(QColor(255,255,255,0)));
55 
56     /* 添加图形 */
57     ui->curve->addGraph();
58     /* 设置画笔颜色 */
59     ui->curve->graph(0)->setPen(QPen(Qt::green));
60     /* 设置画刷 曲线和x轴围成面积的颜色  */
61     //ui->curve->graph(0)->setBrush(QBrush(QColor(255,0,255)));
62     /* 设置右上角图形标注名称 */
63     ui->curve->graph(0)->setName("温度");
64     for(int i = 0; i < 3600; i++)
65     {
66         /* 传入数据*/
67         ui->curve->graph(0)->addData(i, startFireValue);
68     }
69 
70     /* 添加图形 */
71     ui->curve->addGraph();
72     ui->curve->graph(1)->setPen(QPen(Qt::red, 2));
73     ui->curve->graph(1)->setName("升温曲线");
74     /* 刷新曲线 */
75     ui->curve->replot();

 二、更多用法相关链接

https://www.qcustomplot.com/

 

你可能感兴趣的:(Qt-QCustomPlot(画坐标系统)的简单操作)