Pie Chart with QWT

Pie Chart with QWT is a little application able to show a pie chart using QWT library. This idea (allow me to use it) is born because in a project that I was developing I used QWT to make some plots and when I looked for a pie chart there only one chance to get it, using the little pie chart inside Cpu Plot example. This project re-implements the pie chart inside Cpu Plot in order to create a more dynamic and simple one.

In fact, to create a pie chart with this project only the names, the colors and the sector percentages are needed. It acts as a wrapper and any other customization is not needed.

Project description

Github repository: https://github.com/angelosalatino/PieChartWithQWT
Platform: every platform
License: LGPL
Current version: 1.0
Issue tracker: Here

Key features

  • dynamic pie chart creation
  • custom names and colors

Dependencies to build the project

Qt Framework – 4.0 or higher. Download here.
QWT 6.0.1 or higher

Ready to use builds

Just build!

Graphical User Interfaces

At this stage, the GUI is really simple and it is composed by two sections: pie chart and legend. Pie chart is where the chart is drawn (using class PiePlot), whilst legend shows how many sectors is composed the chart, which color have been used and which are the names of each sector.

The legend is at the right of the chart but its position can be changed to left, top, bottom and external. To do that is necessary to change this instruction in PiePlot.cpp:

insertLegend(legend, QwtPlot::RightLegend);

Screenshot from 2014-06-18 11:00:57
Screenshot of the GUI.

Technical information

As it is said in the introduction, The frame below shows the main part of the code. It is important because it is located in main function inside main.cpp.

From line 1 to 6 are defined two objects: pieNames and pieColors.

They are defined as follow:

  • pieNames is a QStringList object and takes as input the sector names: “Plot 1”, “Plot 2” and so on. This names could be changed in what the pie should illustrate. This names will be shown in the right top corner of the GUI.
  • pieColors is a QVector with QColor as type. This object is filled with QColor(int R, int G, int B) object that represents a certain color, where R, G and B equal the proportion of red, green and blue respectively.

Form line 10 to 13, pieValues object is defined. It is a QVector with double as type and it is filled with sector percentage values. Their sum should be less than or equal to 100 (%) to avoid overlaps.

These three object are then processed by PiePlot class (PiePlot.cpp) in order to create, draw and show the graph.

It goes without saying that the size of pieValue must have the same size of pieNames and pieColors.

Thanks

I want to thank whoever wants to use this application, give suggestions, make it bigger and better.