Beispiel #1
0
void PieChart::plot()
{
    chart->removeAllSeries();

    chart->setAnimationOptions( (QChart::AnimationOption)ui->animationComboBox->currentIndex() );
    ui->chartView->setRenderHint(QPainter::Antialiasing, ui->antialiasingCheckBox->isChecked());

    //create series
    QPieSeries * series = new QPieSeries();
//    series->setLabelsVisible();

    series->setHorizontalPosition( ui->hPosSpinBox->value() );
    series->setVerticalPosition( ui->vPosSpinBox->value() );
    series->setPieSize( ui->sizeFactorSpinBox->value() );
    series->setPieStartAngle( ui->startAngleSpinBox->value() );
    series->setPieEndAngle( ui->endAngleSpinBox->value() );
    series->setHoleSize( ui->holeSizeSpinBox->value() );

    foreach( pie_chart_plot_item_t sliceItem, items )
    {
        FlexiPieSlice * slice = new FlexiPieSlice( sliceItem.name, sliceItem.value );
        slice->setExplodeOnHover( ui->explodeSliceCheckBox->isChecked() );
        if(sliceItem.colorIsSet)
        {
            //slice->setPen(QPen(sliceItem.color, 2));
            slice->setBrush(sliceItem.color);
        }
        *series << slice;
    }
Beispiel #2
0
QT_CHARTS_USE_NAMESPACE

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    setMinimumSize(800, 600);

    //! [1]
    QChartView *chartView = new QChartView;
    chartView->setRenderHint(QPainter::Antialiasing);
    QChart *chart = chartView->chart();
    chart->legend()->setVisible(false);
    chart->setTitle("Nested donuts demo");
    chart->setAnimationOptions(QChart::AllAnimations);
    //! [1]

    //! [2]
    qreal minSize = 0.1;
    qreal maxSize = 0.9;
    int donutCount = 5;
    //! [2]

    //! [3]
    for (int i = 0; i < donutCount; i++) {
        QPieSeries *donut = new QPieSeries;
        int sliceCount =  3 + QRandomGenerator::global()->bounded(3);
        for (int j = 0; j < sliceCount; j++) {
            qreal value = 100 + QRandomGenerator::global()->bounded(100);
            QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value);
            slice->setLabelVisible(true);
            slice->setLabelColor(Qt::white);
            slice->setLabelPosition(QPieSlice::LabelInsideTangential);
            connect(slice, &QPieSlice::hovered, this, &Widget::explodeSlice);
            donut->append(slice);
            donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount);
            donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount);
        }
        m_donuts.append(donut);
        chartView->chart()->addSeries(donut);
    }
    //! [3]

    // create main layout
    //! [4]
    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(chartView, 1, 1);
    setLayout(mainLayout);
    //! [4]

    //! [5]
    updateTimer = new QTimer(this);
    connect(updateTimer, &QTimer::timeout, this, &Widget::updateRotation);
    updateTimer->start(1250);
    //! [5]
}