天天看點

Qt基于Qml圖餅定制示範

 示範效果

Qt基于Qml圖餅定制示範

代碼塊與對應面 

Qt基于Qml圖餅定制示範

 主要使用元件 : ChartView

PieSeries 主要用于餅塊配置,

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtCharts 2.3

ApplicationWindow {
    visible: true
    width: 800
    height: 600
    title: qsTr("Qt基于Qml圖餅定制示範")

    ChartView {
        anchors.fill: parent
        //theme: ChartView.ChartThemeQt  //使用樣式的話 backgroundColor無效
        antialiasing: true
        legend.visible: false
        animationOptions: ChartView.AllAnimations
        backgroundColor: "black"
        titleColor: "white"
        title: "Qml ChartView "
        PieSeries {
            id: pieSeries
            PieSlice {
                borderColor: "#AAAAAA"
                color: "#00FF00"
                label: qsTr("C++")
                labelVisible: true
                value: 56.6
                labelColor: "green"
            }
            PieSlice {
                borderColor: "#AAAAAA"
                color: "#FF00FF"
                label: qsTr("C#")
                labelVisible: true
                value: 30
                labelColor: "red"
            }
            PieSlice {
                borderColor: "#AAAAAA"
                color: "#FFFF00"
                label: qsTr("QML")
                labelVisible: true
                value: 13.4
                labelColor: "blue"
            }
        }
    }
}