summaryrefslogtreecommitdiffstats
path: root/examples/charts/chartsgallery/donutwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/charts/chartsgallery/donutwidget.cpp')
-rw-r--r--examples/charts/chartsgallery/donutwidget.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/charts/chartsgallery/donutwidget.cpp b/examples/charts/chartsgallery/donutwidget.cpp
new file mode 100644
index 00000000..2bee9974
--- /dev/null
+++ b/examples/charts/chartsgallery/donutwidget.cpp
@@ -0,0 +1,34 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "donutwidget.h"
+
+#include <QChart>
+#include <QPieSeries>
+#include <QPieSlice>
+
+DonutWidget::DonutWidget(QWidget *parent)
+ : ContentWidget(parent)
+{
+ //![1]
+ auto series = new QPieSeries;
+ series->setHoleSize(0.35);
+ series->append("Protein 4.2%", 4.2);
+ QPieSlice *slice = series->append("Fat 15.6%", 15.6);
+ slice->setExploded();
+ slice->setLabelVisible();
+ series->append("Other 23.8%", 23.8);
+ series->append("Carbs 56.4%", 56.4);
+ //![1]
+
+ //![2]
+ auto chart = new QChart;
+ chart->setTitle("Donut with a lemon glaze (100g)");
+ chart->addSeries(series);
+ chart->legend()->setAlignment(Qt::AlignBottom);
+ chart->setTheme(QChart::ChartThemeBlueCerulean);
+ chart->legend()->setFont(QFont("Arial", 7));
+
+ createDefaultChartView(chart);
+ //![2]
+}