QPolarChart隐藏径向刻度标签

时间:2019-04-15 13:03:18

标签: c++ qt qt5 qtchart

我创建了一个QPolarChart,我想隐藏径向刻度线标签,但保留刻度线圈。我只是想摆脱显示“ 0.0”,“ 20.0”等的文本。我试图更改标签格式,但这没有用。

这是我尝试过的最小示例:

#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QPolarChart>
#include <QtCharts/QValueAxis>

QT_CHARTS_USE_NAMESPACE

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QPolarChart *chart = new QPolarChart();

    QValueAxis *angularAxis = new QValueAxis();
    angularAxis->setTickCount(13);
    angularAxis->setLabelFormat("%d");
    angularAxis->setRange(0, 361);
    chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular);


    QValueAxis *radialAxis = new QValueAxis();
    radialAxis->setTickCount(10);
    radialAxis->setLabelFormat(""); // <-- what do I have to add here?
    radialAxis->setRange(0, 90);
    chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial);


    chart->legend()->setVisible(false);

    QLineSeries *series = new QLineSeries();
    *series << QPointF(0, 0) << QPointF(90, 22.5) << QPointF(180, 45) << QPointF(270, 67.5) << QPointF(360, 90);

    chart->addSeries(series);

    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    chart->legend()->hide();

    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(400, 400);
    window.show();

    return a.exec();
}

这是结果的样子。 我想摆脱径向轴标签(“ 0.0”,“ 10.0” ...“ 90.0”) example

1 个答案:

答案 0 :(得分:1)

技巧是将labelFormat设置为" "或无效格式,例如"@"

radialAxis->setLabelFormat(" ");
# or radialAxis->setLabelFormat("@");

enter image description here