我想用QChart,QLogValueAxis画一个上图的坐标轴,结果画成这样了:
横坐标轴不对,代码如下:
QLineSeries* series = new QLineSeries();
series->append(250, 10);
series->append(500, 20);
series->append(1000, 30);
series->append(2000, 40);
series->append(4000, 50);
series->append(8000, 60);
chart = new QChart(); //创建chart
chart->addSeries(series);
// 使用 QLogValueAxis 设置对数刻度轴
QLogValueAxis* axisX = new QLogValueAxis();
axisX->setBase(2);
axisX->setTitleText("Frequency (Hz)");
axisX->setLabelFormat("%d"); // 设置标签格式
axisX->setMinorTickCount(1); // 取消小刻度
axisX->setRange(250, 8000);
QValueAxis* axisY = new QValueAxis();
axisY->setRange(0, 70);
axisY->setTitleText(tr("Gain(db)"));
axisY->setTickCount(8);
axisY->setLabelFormat("%.1f"); //标签格式
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisY);
chart->setAnimationOptions(QChart::SeriesAnimations);
chart->layout()->setContentsMargins(0, 0, 0, 0);//设置外边界全部为0
chart->setMargins(QMargins(0, 0, 0, 0));//设置内边界全部为0
chart->setBackgroundRoundness(0); //设置背景区域无圆角
ui->chartView->setChart(chart); //为ChartView设置chart
ui->chartView->setRenderHint(QPainter::Antialiasing);
该怎么处理,横坐标轴可以实现图一效果,谢谢。