QPolarChart and QLineSeries error when plotting line over 0/360 degree

175 views Asked by At

I am trying to create a polar plot with a line series. Sometimes the line will go from ie. 330° to 30°. However the plotted line has an additional point at (0,0).

Is there a way to change that behavior or might that be a bug due to the discontinuity of 360° being equivalent of 0°.

I expect this to be a common scenario, but i did not found anything about this problem online. (However all the examples avoid this 360°/0° transition or start at 0° and end at 360°.)

This is the output i get from the plot: Polar Plot

This minimal example was generated with the following code:

#include "MainWindow.hpp"
#include "./ui_MainWindow.h"

#include <QChart>
#include <QPolarChart>
#include <QLineSeries>
#include <QValueAxis>
#include <QChartView>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    auto series = new QtCharts::QLineSeries();
    series->append(330,60);
    //series->append(360,60); (with both lines enabled the problem still occurs)
    //series->append(0,60);
    series->append(30,60);
    series->append(60,60);
    series->append(90,60);    

    auto chart = new QtCharts::QPolarChart();
    chart->addSeries(series);

    auto angularAxis = new QtCharts::QValueAxis();
    angularAxis->setTickCount(9);
    angularAxis->setMin(0);
    angularAxis->setMax(360);
    angularAxis->setLabelFormat("%.1f");
    chart->addAxis(angularAxis, QtCharts::QPolarChart::PolarOrientationAngular);
    series->attachAxis(angularAxis);

    auto *radialAxis = new QtCharts::QValueAxis();
    radialAxis->setTickCount(9);
    radialAxis->setMin(0);
    radialAxis->setMax(90);
    radialAxis->setLabelFormat("%.1f");
    chart->addAxis(radialAxis, QtCharts::QPolarChart::PolarOrientationRadial);
    series->attachAxis(radialAxis);

    auto view = new QtCharts::QChartView(chart);

    centralWidget()->layout()->addWidget(view);
}

MainWindow::~MainWindow()
{
    delete ui;
}
0

There are 0 answers