Personalizando visualizações de gráficos com QML

Captura de tela mostrando um gráfico com duas séries de dados: uma é um gráfico de pizza com um gradiente azul e a outra é um gráfico de linhas com um ponto laranja

Observação: Isso faz parte do exemplo “Galeria de gráficos com QML ”.

Aqui, mostramos como criar uma roda da sorte personalizando uma série de gráficos de pizza.

Primeiro, criamos o ChartView e algumas séries.

ChartView {
    id: chartView
    anchors.fill: parent
    title: "Wheel of Fortune"
    legend.visible: false
    antialiasing: true

    PieSeries {
        id: wheelOfFortune
        horizontalPosition: 0.3
    }

    SplineSeries {
        id: splineSeries
    }

    ScatterSeries {
        id: scatterSeries
    }
}

Os dados do aplicativo são gerados no método `Component.onCompleted` do retângulo principal:

Component.onCompleted: {
    __intervalCoefficient = Math.random() + 0.25;

    for (var i = 0; i < 20; i++)
        wheelOfFortune.append("", 1);

    var interval = 1;
    for (var j = 0; interval < 800; j++) {
        interval = __intervalCoefficient * j * j;
        splineSeries.append(j, interval);
    }
    chartView.axisX(scatterSeries).max = j;
    chartView.axisY(scatterSeries).max = 1000;
}

As personalizações a seguir são realizadas repetidamente por meio de um temporizador. Para destacar uma das fatias do gráfico circular por vez, modificamos sua propriedade `exploded`:

wheelOfFortune.at(index).exploded = false;
root.__activeIndex++;
index = root.__activeIndex % wheelOfFortune.count;
wheelOfFortune.at(index).exploded = true;

Em seguida, uma animação usando uma série de dispersão com um ponto de dados:

scatterSeries.clear();
scatterSeries.append(root.__activeIndex, interval);
scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000");
scatterSeries.markerSize += 0.5;

Quando a roda da sorte para, fazemos a fatia ativa piscar, alterando suas cores.

// Switch the colors of the slice and the border
wheelOfFortune.at(index).borderWidth = 2;
switchColor = wheelOfFortune.at(index).borderColor;
wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color;
wheelOfFortune.at(index).color = switchColor;

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.