Qt QChart 創(chuàng)建圖表的實現(xiàn)方法
更新時間:2020年12月23日 09:40:04 作者:咸魚Doyoung
這篇文章主要介紹了Qt QChart 創(chuàng)建圖表的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
本文主要介紹了Qt QChart 創(chuàng)建圖表,分享給大家,也給自己留個筆記,廢話不多說,具體如下:
效果
流程
代碼
1. 餅圖
// 保存多個扇形 QList<QPieSlice *> slices; for (int i = 1; i <= 10; ++i) { // 創(chuàng)建一個扇形 QPieSlice * slice = new QPieSlice(QString::number(i),i); slices << slice; } // 創(chuàng)建一個餅圖系列 QPieSeries * pieSeries = new QPieSeries; // 當鼠標懸浮時設置標簽可見,設置餅圖扇形分離 QObject::connect(pieSeries,&QPieSeries::hovered , [](QPieSlice *slice, bool state) { slice->setLabelVisible(state); slice->setExploded(state); }); // 將所有扇形所加到餅圖中 pieSeries->append(slices); // 創(chuàng)建一個圖表 QChart * chart = new QChart; // 設置標題 chart->setTitle(QStringLiteral("餅圖")); // 設置動畫 chart->setAnimationOptions(QChart::AllAnimations); // 設置圖表的系列 chart->addSeries(pieSeries); // 創(chuàng)建圖表視圖,顯示圖表 pView = new QChartView(chart); // 設置抗鋸齒 pView->setRenderHint(QPainter::Antialiasing); // 添加圖表視圖到布局 QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(pView);
2. 柱圖
// 保存柱集合 QList<QBarSet *> sets; for (int i = 1; i <= 5; ++i) { // 創(chuàng)建一個柱集合 QBarSet * set = new QBarSet(QString("set").append(QString::number(i))); QList<qreal> values; for (int j = 1; j <= 5; ++j) { values << qrand()%100; qDebug() << values; } set->append(values); sets << set; } // 創(chuàng)建一個柱圖系列 QBarSeries * barSeries = new QBarSeries; // 添加柱集合 barSeries->append(sets); QChart * chart = new QChart; chart->setTitle(QStringLiteral("柱狀圖")); chart->setAnimationOptions(QChart::AllAnimations); chart->addSeries(barSeries); pView = new QChartView(chart); pView->setRenderHint(QPainter::Antialiasing); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(pView);
3. 折/曲線圖
// 創(chuàng)建并保存點信息 QList<QPointF> points; points << QPointF(0, -1) << QPointF(2, 2) << QPointF(3, 5) << QPointF(5, -5) << QPointF(6, 0) << QPointF(7, 3); // 創(chuàng)建線圖系列 QLineSeries * lineSeries = new QLineSeries; // 曲線 //QSplineSeries * lineSeries = new QSplineSeries; // 追加點 lineSeries->append(points); QChart * chart = new QChart; chart->setTitle(QStringLiteral("線圖")); chart->setAnimationOptions(QChart::AllAnimations); chart->addSeries(lineSeries); pView = new QChartView(chart); pView->setRenderHint(QPainter::Antialiasing); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(pView);
4. 區(qū)域圖
QList<QPointF> pointsLower; pointsLower << QPointF(0, -1) << QPointF(2, 2) << QPointF(3, 5) << QPointF(5, -5) << QPointF(6, 0) << QPointF(7, 3); // 創(chuàng)建一條線 QLineSeries * lineSeriesLower = new QLineSeries; lineSeriesLower->append(pointsLower); QList<QPointF> pointsUpper; pointsUpper << QPointF(0, -1) << QPointF(2, 4) << QPointF(3, 3) << QPointF(5, 3) << QPointF(6, 1) << QPointF(7, 5); // 創(chuàng)建另一條線 QLineSeries * lineSeriesUpper = new QLineSeries; lineSeriesUpper->append(pointsUpper); // 兩條線組成面 QAreaSeries * areaSeries = new QAreaSeries(lineSeriesLower, lineSeriesUpper); QChart * chart = new QChart; chart->setTitle(QStringLiteral("區(qū)域圖")); chart->setAnimationOptions(QChart::AllAnimations); chart->addSeries(areaSeries); pView = new QChartView(chart); pView->setRenderHint(QPainter::Antialiasing); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(pView);
到此這篇關于Qt QChart 創(chuàng)建圖表的實現(xiàn)方法的文章就介紹到這了,更多相關Qt QChart 創(chuàng)建圖表 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
- 基于PyQt5制作一個數(shù)據(jù)圖表生成器
- Qt繪制圖表的實現(xiàn)
- Qt圖形圖像開發(fā)之曲線圖表模塊QChart庫一個chart中顯示兩條曲線詳細方法與實例
- Qt圖形圖像開發(fā)之曲線圖表模塊QChart庫坐標軸和數(shù)據(jù)不對應、密集的散點圖無法顯示問題解決方法
- Qt圖形圖像開發(fā)曲線圖表模塊QChart庫縮放/平移詳細方法與實例
- Qt圖形圖像開發(fā)之曲線圖表模塊QChart庫讀取/設置X軸的顯示區(qū)間
- Qt圖形圖像開發(fā)曲線圖表模塊QChart庫基本用法、各個類之間的關系說明
- Qt圖形圖像開發(fā)之曲線圖表庫QChart編譯安裝詳細方法與使用實例
- Qt實現(xiàn)簡單折線圖表
相關文章
C++動態(tài)規(guī)劃實現(xiàn)查找最長公共子序列
這篇文章主要介紹了C++動態(tài)規(guī)劃最長公共子序列,在動態(tài)規(guī)劃中,你要將某個指標最大化。在這個例子中,你要找出最長公共子序列2022-06-06VC++6.0實現(xiàn)直線掃描轉(zhuǎn)換的圖文教程
這篇文章主要給大家介紹了關于VC++6.0實現(xiàn)直線掃描轉(zhuǎn)換的相關資料,文中通過圖文將實現(xiàn)的步驟一步步介紹的非常詳細,對大家學習或者使用VC++6.0具有一定的參考學習價值,需要的朋友可以參考下2023-01-01