受欢迎的博客标签

QT Creating Charts Using QML

Published
https://doc-snapshots.qt.io/qtcharts/qtcharts-qmlchart-example.html Creating Charts Using QML Creating each chart type begins with the creation of a ChartView. To create a pie, we use the PieSeries API together with a few PieSlices: ChartView{id:charttitle:"Top-5 car brand shares in Finland"anchors.fill:parentlegend.alignment:Qt.AlignBottomantialiasing:truePieSeries{id:pieSeriesPieSlice{label:"Volkswagen";value:13.5}PieSlice{label:"Toyota";value:10.9}PieSlice{label:"Ford";value:8.6}PieSlice{label:"Skoda";value:8.2}PieSlice{label:"Volvo";value:6.8}}}Component.onCompleted:{// You can also manipulate slices dynamicallyothersSlice=pieSeries.append("Others",52.0);pieSeries.find("Volkswagen").exploded=true;} To create a chart with a line series: ChartView{title:"Line"anchors.fill:parentantialiasing:trueLineSeries{name:"LineSeries"XYPoint{x:0;y:0}XYPoint{x:1.1;y:2.1}XYPoint{x:1.9;y:3.3}XYPoint{x:2.1;y:2.1}XYPoint{x:2.9;y:4.9}XYPoint{x:3.4;y:3.0}XYPoint{x:4.1;y:3.3}}}  .