Results 1 to 3 of 3

Thread: Pie Chart Implementation

  1. #1
    Join Date
    Feb 2014
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Pie Chart Implementation

    Chart Info: http://www.ics.com/files/qtdocs/itemviews-chart.html

    I have copied Pieview.h and .cpp. I keep my data in a vector, so don't need chart.qrc.

    My Abstract Model def:

    Qt Code:
    1. absModel = new QStandardItemModel(8, 2, this);
    2. absModel->setHeaderData(0, Qt::Horizontal, tr("Age"));
    3. absModel->setHeaderData(1, Qt::Horizontal, tr("Gender"));
    4.  
    5. for(int row=0; row<myFace.size(); row++){
    6. absModel->setData(absModel->index(row, 0, QModelIndex()),
    7. myFace.at(row).age);
    8. absModel->setData(absModel->index(row, 1, QModelIndex()),
    9. myFace.at(row).gender);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Both "age" and "gender" contain integer values. I want to show that with 2 pie charts. One of them show Ages and other one shows genders. (0:male 1:female)

    ViewSetup:

    Qt Code:
    1. QTableView *table = new QTableView;
    2. QListView *list = new QListView;
    3. agePieChart = new PieView;
    4. genderPieChart = new PieView;
    5. ui->splitter->addWidget(list);
    6. ui->splitter->addWidget(table);
    7. ui->splitter->addWidget(agePieChart);
    8. ui->splitter->addWidget(genderPieChart);
    9. ui->splitter->setStretchFactor(0, 0);
    10. ui->splitter->setStretchFactor(1, 1);
    11.  
    12. table->setModel(absModel);
    13. list->setModel(absModel);
    14. agePieChart->setModel(absModel);
    15. genderPieChart->setModel(absModel);
    16. QItemSelectionModel *selectionModel = new QItemSelectionModel(absModel);
    17. table->setSelectionModel(selectionModel);
    18. list->setSelectionModel(selectionModel);
    19. agePieChart->setSelectionModel(selectionModel);
    20. genderPieChart->setSelectionModel(selectionModel);
    21. QHeaderView *headerView = table->horizontalHeader();
    22. headerView->setStretchLastSection(true);
    To copy to clipboard, switch view to plain text mode 
    That code shows ListView and TableView in splitter but Charts are blank page.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Pie Chart Implementation

    Have you had a look at the code?

    As far as I can tell the pie view expects column 0 to be a color and column 1 to be the value of the segment.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Pie Chart Implementation

    I have adapted my code to example, and it worked.

Similar Threads

  1. Chart and diagrams for Qt
    By bred in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2011, 21:10
  2. kd chart question
    By yunpeng880 in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2009, 02:43
  3. how much about kd chart
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 10:54
  4. what chart for qt?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2009, 12:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.