LibEngsas
echarts.cpp

This example demonstrates the usage of EChartPie and EChartLine to draw pie and line charts.The example creates a main window with an central widget, which contains both charts. The charts can be exported by the Export action within there context menu.

example-echarts-screenshot.png

The main window is a class with name MainWindow, defined in file mainwindow.h as follows:

The header contains only two custom functions. The first creates the pie chart widget and the second the line chart widget. Also a few private pointer are defined, to access the chart widgets and the central widget. The implementation is done within mainwindow.cpp.

The first thing done in the constructor is the change of the window title. Afterwards a new central widget is created, a layout added and populated to the main window by calling setCentralWidget(). Then addChartPie() and addChartLine() creates the chart widgets.

The pie chart widget is created and added to the layout of the widget, after the special LibEngsas slots from EWidgets are connected (like error, warning and information signals) by calling connectByPass().

After settings the chart title with EChartBase::setChartTitle(), the input and output is configured. EChartPie::setPercent() is set to true, because the input values are already percent values. The precision is set to two digits, which is used to determine the number of shown digits in the chart later on. The values are added afterwards. For pie charts, every data set consists of an EChartValues object, which only contains one x-value. Therefore the y value is set to 0.

The first lines adding the line chart, are similar to the ones of the pie chart. Since the line chart has an x and y-axis, those needs to be configured. This is done by setting the tick values for both axis and their title. The date of the measured market shared is displayed on the x-axis in format MM.YY. On the y-axis, the market share in percent is displayed. Since the most common browser reaches 51 percent, the highest tick is the 50.

Within an EChartLine, each line is represanted by one EChartValues object. Therefore an EChartValues object is created and value pairs for one browser (one line in the chart) are added. Each pair consists of a date as x-value and the market share at that time as y-value. After adding those pairs, the object is added to the chart by calling EChartBase::addDataSet(). The line is labeld with the specified string.

echarts.cpp contains the main() function to execute QApplication and load the MainWindow.