Chartwork

Chart Widgets for Qt

Fork me on GitHub

Demo Video

Installation

Ubuntu

Chartwork runs on Ubuntu 14.04 (64 bit) and requires Qt 5.

Chartwork 1.02

  1. Double-click the .deb file to open the Software Center.

  2. Click ›Install‹ and enter your password.

Windows

Chartwork runs on Windows 7 and newer and requires at least Qt 5.4.

Qt 5 Chartwork 1.1.0 (32 bit) Chartwork 1.1.0 (64 bit)

  1. Download and install the free version of Visual Studio, Visual Studio Community.

    Visual Studio is required to build apps with Chartwork in Qt Creator.

  2. Download the open-source version of Qt 5 and Chartwork.

    If you are running 32-bit Windows, install the 32-bit versions of Qt 5 and Chartwork. On 64-bit Windows, install the 64-bit versions instead.

  3. Install Qt 5.

  4. Run the Chartwork installer. Click ›Open Qt Directory‹ and select the location where you installed Qt 5 (e. g., C:\Qt).

  5. Click ›Install‹.

If Qt Creator Crashes Immediately

Try turning off the Welcome screen by adding the following command-line argument to the desktop link: [...]\qtcreator.exe -noload Welcome.

Help With Compiler Set-Up

If you need help during the configuration steps shown below, have a look at the official Qt Creator documentation page.

Mac OS X

Chartwork runs on Mac OS X 10.7 (Lion) and newer and requires Qt 5.4.

Qt 5 Chartwork 1.1.0

  1. Install Xcode from the App Store.

    Xcode ships a compiler that can be used with Qt Creator.

  2. Download the open-source version of Qt 5 and Chartwork.

  3. Install Qt 5.

  4. Run the Chartwork installer. Click ›Open Qt Directory‹ and select the location where you installed Qt 5 (e. g., /Users/user/Qt5.4.1).

  5. Click ›Install‹.

    You can now start Qt Creator from the Qt directory.

From Sources

Chartwork Sources

For instructions on how to build Chartwork from sources, see the readme on GitHub.

Build Your App

Starter Project 1.1.0

Pie Charts

Visual Configuration

Pie Chart
Pie Chart Configuration Options in Qt Designer.
setTitle(QString)
setLabels(QStringList)
setShowKey(bool)
setKeyScale(double)
setShowPercentage(bool)
setPrecision(int)
setColor0(QColor)
setColor1(QColor)
setColor2(QColor)
...

Adding Slices

To change the number of slices, click on the option labels. In the pop-up menu, you can add or remove slices and change their labels.

Pie Chart
Pie Chart

Hiding the Key

By removing the checkmark next to showKey, you can hide the key. Instead, you can also reduce the dimensions of the key with keyScale.

Pie Chart
Pie Chart

Percentage Precision

You can change the number of decimal places of the percentages with the precision option.

Hiding Percentages

By removing the checkmark next to showPercentage, you can hide the percentages.

Pie Chart
Pie Chart

Changing the Color Palette

At the bottom of the options panel, you can change the color palette (via the options color0 to color7). color0 will be used for the first slice, and so forth.

Pie Chart
Pie Chart

Add Your Data

To resize the slice labeled as ›C‹ to a value of 35, just write:

ui->pieChart->setValue("C", 35.0);

Alternatively, you can address slices by their index, starting with 0. In our example, ›C‹ has index 2, and thus you can write:

ui->pieChart->setValue(2, 35.0);

You can also set the values of all slices simultaneously, e. g., to 100:

ui->pieChart->setAllValues(100.0);

Reading the size of a slice in the pie chart is similar to writing it—you can address it either by its label (›C‹) or its index (2):

double value1 = ui->pieChart->value("C");
	double value2 = ui->pieChart->value(2);

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Grid Charts

Visual Configuration

Grid Chart
Grid Chart Configuration Options in Qt Designer.
setTitle(QString)
setShowKey(bool)
setKeyScale(double)
setAntialiasing(bool)
setGridSize(QSize)
setMinValue(double)
setMaxValue(double)
setPrecision(int)
setNumberOfColors(int)
setColor0(QColor)
setColor1(QColor)
setColor2(QColor)
...

Changing the Resolution

To change the number of columns or rows, click on the plus symbol next to gridSize. The options Width and Height determine the grid resolution.

Grid Chart
Grid Chart

Minimum and Maximum Value

The minimum and maximum values determine the range of values that will be mapped to the color palette. Cells with the value minValue will be displayed with the first color color0, the value maxValue will be shown having the last color and in-between values will be blended between the colors in the color palette.

Grid Chart
Grid Chart

Key Precision

You can change the number of decimal places in the key with the precision option.

Hiding the Key

By removing the checkmark next to showKey, you can hide the key. Instead, you can also reduce the dimensions of the key with keyScale.

Grid Chart
Grid Chart

Number of Colors

If you need more or less than 5 color steps, adjust the numberOfColors option.

Grid Chart
Grid Chart

Changing the Color Palette

At the bottom of the options panel, you can change the color palette (via the options color0 to color7). color0 will be used for the first step, and so forth.

Grid Chart
Grid Chart

Add Your Data

To set the value of cell [5, 10] to 75, write:

ui->gridChart->setValue(5, 10, 75.0);

Origin

The origin [0, 0] of the grid chart corresponds to the top-left corner.

You can also set the values of all cells simultaneously, e. g., to 0:

ui->gridChart->setAllValues(0.0);

Reading the value of a cell is similar to writing it:

double value = ui->gridChart->value(5, 10);

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Grouped Bar Charts

Visual Configuration

Grouped Bar Chart
Grouped Bar Chart Configuration Options in Qt Designer.
setTitle(QString)
setShowKey(bool)
setKeyScale(double)
setYMax(double)
setYPrecision(int)
setGroupLabels(QStringList)
setSubGroupLabels(QStringList)
setColor0(QColor)
setColor1(QColor)
setColor2(QColor)
...

Adding Bars and Groups

Grouped bar charts display bars in different groups.

The option groupLabels defines how many groups will be displayed (see screenshot in the middle below). By clicking on this option, a pop-up menu will show up in which you can add, remove, and rename groups.

In addition, you can configure the number of bars per group with the option subGroupLabels (see the right screenshot). In analogy to groups, you can add, remove, and rename them.

Grouped Bar Chart
Grouped Bar Chart
Grouped Bar Chart

Maximum Value and Precision

You can modify the maximum value of the scale with yMax (the minimum is always 0). The precision of the scale can be changed with yPrecision.

Grouped Bar Chart
Grouped Bar Chart

Hiding the Key

By removing the checkmark next to showKey, you can hide the key. Instead, you can also reduce the dimensions of the key with keyScale.

Grouped Bar Chart
Grouped Bar Chart

Changing the Color Palette

At the bottom of the options panel, you can change the color palette (via the options color0 to color7). color0 will be used for the first bar in each group, and so forth.

Grouped Bar Chart
Grouped Bar Chart

Add Your Data

To resize the bar labeled as ›C‹ in group ›Group 1‹ to a value of 15, just write:

ui->groupedBarChart->setValue("Group 1", "C", 15.0);

Alternatively, you can address groups and subgroups by their index, starting with 0. In our example, ›Group 1‹ has index 0 and ›C‹ has index 2, and thus you can write:

ui->groupedBarChart->setValue(0, 2, 15.0);

You can also set the values of all bars simultaneously, e. g., to 100:

ui->groupedBarChart->setAllValues(100.0);

Reading the size of a bar in the bar chart is similar to writing it—you can address it either by labels (›Group 1‹, ›C‹) or indices (0, 2):

double value1 = ui->groupedBarChart->value("Group 1", "C");
	double value2 = ui->groupedBarChart->value(0, 2);

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Stacked Bar Charts

Visual Configuration

Stacked Bar Chart
Stacked Bar Chart Configuration Options in Qt Designer.
setTitle(QString)
setShowKey(bool)
setKeyScale(double)
setYMax(double)
setYPrecision(int)
setNormalize(bool)
setGroupLabels(QStringList)
setSubGroupLabels(QStringList)
setColor0(QColor)
setColor1(QColor)
setColor2(QColor)
...

Adding Bars and Parts

Stacked bar charts display several bars with stacked subgroups.

The option groupLabels defines how many bars will be displayed (see screenshot in the middle below). By clicking on this option, a pop-up menu will show up in which you can add, remove, and rename bars.

In addition, you can configure the number of stacked parts per bar with the option subGroupLabels (see the right screenshot). In analogy to bars, you can add, remove, and rename them.

Stacked Bar Chart
Stacked Bar Chart
Stacked Bar Chart

Normalized Data

By default, data in stacked bar charts are normalized to 100 %. You can disable this behavior by removing the checkmark next to normalize.

Stacked Bar Chart
Stacked Bar Chart

Maximum Value and Precision

When normalize is disabled, you can modify the maximum value of the scale with yMax (the minimum is always 0). The precision of the scale can be changed with yPrecision.

Not For Normalized Bar Charts

These options have no effect when you use normalize.
Stacked Bar Chart
Stacked Bar Chart

Hiding the Key

By removing the checkmark next to showKey, you can hide the key. Instead, you can also reduce the dimensions of the key with keyScale.

Stacked Bar Chart
Stacked Bar Chart

Changing the Color Palette

At the bottom of the options panel, you can change the color palette (via the options color0 to color7). color0 will be used for the first part in each bar, and so forth.

Stacked Bar Chart
Stacked Bar Chart

Add Your Data

To resize the part labeled as ›C‹ in bar ›G1‹ to a value of 65, just write:

ui->stackedBarChart->setValue("G1", "C", 65.0);

Alternatively, you can address bars and parts by their index, starting with 0. In our example, ›G1‹ has index 0 and ›C‹ has index 2, and thus you can write:

ui->stackedBarChart->setValue(0, 2, 65.0);

You can also set the values of all parts simultaneously, e. g., to 100:

ui->stackedBarChart->setAllValues(100.0);

Reading the size of a part in the bar chart is similar to writing it—you can address it either by labels (›G1‹, ›C‹) or indices (0, 2):

double value1 = ui->stackedBarChart->value("G1", "C");
	double value2 = ui->stackedBarChart->value(0, 2);

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Histograms

Visual Configuration

Histogram
Histogram Configuration Options in Qt Designer.
setTitle(QString)
setShowKey(bool)
setKeyScale(double)
setXMin(double)
setXMax(double)
setXStep(double)
setXPrecision(int)
setYMax(double)
setYPrecision(int)
setColor(QColor)
...

Changing the Number of Bars

Histograms display bars for a range of values, specified by the options xMin, xMax, and xStep. For instance, you can reproduce the right screenshot if you choose the range 500 to 1000 and steps of 50.

Furthermore, you can change the number of decimal places in the bar labels with xPrecision.

Histogram
Histogram

Maximum Value and Precision

You can modify the maximum value of the y scale with yMax (the minimum is always 0). The precision of the scale can be changed with yPrecision.

Histogram
Histogram

Changing the Color

You can change the color of the histogram via the option color.

Histogram
Histogram

Add Your Data

To resize the 3rd bar in the histogram to 40, write:

ui->histogram->setValue(2, 40.0);

You can also set the values of all parts simultaneously, e. g., to 100:

ui->histogram->setAllValues(100.0);

Reading the size of a bar in the histogram is similar to writing it:

double value = ui->histogram->value(2);

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Scatter Plots

Visual Configuration

Scatter Plot
Scatter Plots Configuration Options in Qt Designer.
setTitle(QString)
setShowKey(bool)
setKeyScale(double)
setXMin(double)
setXMax(double)
setXPrecision(int)
setYMin(double)
setYMax(double)
setYPrecision(int)
setLabels(QStringList)
setSymbolSize(int)
setColor0(QColor)
setSymbol0(Symbol::Type)
setColor1(QColor)
setSymbol1(Symbol::Type)
setColor2(QColor)
setSymbol2(Symbol::Type)
...

Adding Data Series

Scatter Plots can display different data series using different colors and symbols. To add or remove data series, click on the option labels and modify the entries in the pop-up window that shows up.

Scatter Plot
Scatter Plot

Axes and Precision

You can choose minimum and maximum values for both axes using xMin, xMax, yMin, and yMax, respectively. The precision of the scales can be changed with xPrecision and yPrecision.

Scatter Plot
Scatter Plot

Hiding the Key

By removing the checkmark next to showKey, you can hide the key. Instead, you can also reduce the dimensions of the key with keyScale.

Scatter Plot
Scatter Plot

Changing the Symbols and Color Palette

At the bottom of the options panel, you can change the symbols and the color palette (via the options color0 to color7 and symbol0 to symbol7). color0 and symbol0 will be used for the first data series, and so forth.

Scatter Plot
Scatter Plot
List of Available Symbols
Circle Symbol CircleOutline Symbol
Square Symbol SquareOutline Symbol
Diamond Symbol DiamondOutline Symbol
Plus Symbol Cross Symbol

Making Symbols Bigger or Smaller

With the option symbolSize, you can increase or decrease the size of the symbols.

Scatter Plot
Scatter Plot

Add Your Data

To add the data point [5, 20] to your data series ›Baseline‹, just write:

ui->scatterPlot->addData("Baseline", 5.0, 20.0);

Alternatively, you can address data series by their index, starting with 0. In our example, ›Baseline‹ has index 0, and thus you can write:

ui->scatterPlot->addData(0, 5.0, 20.0);

To clear the whole data series ›Baseline‹, write one of the following:

ui->scatterPlot->clearData("Baseline");
	ui->scatterPlot->clearData(0);

You can also clear all data series of your plot simultaneously:

ui->scatterPlot->clearAllData();

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Line Plots

Visual Configuration

Line Plot
Line Plots Configuration Options in Qt Designer.
setTitle(QString)
setShowKey(bool)
setKeyScale(double)
setXMin(double)
setXMax(double)
setXPrecision(int)
setYMin(double)
setYMax(double)
setYPrecision(int)
setLabels(QStringList)
setLineWidth(double)
setColor0(QColor)
setColor1(QColor)
setColor2(QColor)
...

Adding Data Series

Line Plots can display different data series using differently colored lines. To add or remove data series, click on the option labels and modify the entries in the pop-up window that shows up.

Line Plot
Line Plot

Axes and Precision

You can choose minimum and maximum values for both axes using xMin, xMax, yMin, and yMax, respectively. The precision of the scales can be changed with xPrecision and yPrecision.

Line Plot
Line Plot

Hiding the Key

By removing the checkmark next to showKey, you can hide the key. Instead, you can also reduce the dimensions of the key with keyScale.

Line Plot
Line Plot

Changing the Color Palette

At the bottom of the options panel, you can change the color palette (via the options color0 to color7). color0 will be used for the first data series, and so forth.

Line Plot
Line Plot

Making Lines Thicker or Thinner

With the option lineWidth you can increase or decrease the width of the lines.

Line Plot
Line Plot

Add Your Data

To add the data point [5, 20] to your data series ›Baseline‹, just write:

ui->linePlot->addData("Baseline", 5.0, 20.0);

Alternatively, you can address data series by their index, starting with 0. In our example, ›Baseline‹ has index 0, and thus you can write:

ui->linePlot->addData(0, 5.0, 20.0);

To clear the whole data series ›Baseline‹, write one of the following:

ui->linePlot->clearData("Baseline");
	ui->linePlot->clearData(0);

You can also clear all data series of your plot simultaneously:

ui->linePlot->clearAllData();

Call Update

After setting all your data in a plot, call ui->myChart->update(). Else, your changes won’t be visible immediately.

Troubleshooting

I Don’t See My Data

There are two main reasons why you might not see your data, even though you called the functions listed above: wrongly set up axes and missing drawing updates.

Axis Set-Up Is Wrong

Assume you have set up a scatter plot ranging from −1 to +1 both in x and y. If you add a data point at [50, 50], it will obviously not be painted.

If you don’t see your data, first make sure you configured the charts to use the same value range your own code uses.

Charts Not Updated

If you still don’t see any changes in your application, you might have forgotten to call the update() method after setting your data in the chart. If you don’t call update(), the chart will not be painted.

Do it like this:

for (int x = 0; x < 20; x++)
	for (int y = 0; y < 20; y++)
		ui->gridChart->setValue(x, y, myValue);

ui->gridChart->update();

Improving Performance

If you use for loops, call update() once at the end (like shown above) to improve performance.

Error Messages

If you call functions with invalid values, you might get an error message. The following explains the sources of these errors and how to fix them.

Out-of-Range Error

[Error] Access to ScatterPlot 'scatterPlot' at dataSeries = 5 is out of range.
        Allowed values are dataSeries = 0...2 here.

In this example, the programmer has tried to write a value in the 6th data series in his scatter plot. However, he has created only 3, causing an out-of-range error.

  • Check whether the value you tried to access is valid.
  • In pie charts, add a new slice label if necessary.
  • In grid charts, increase the grid size if necessary.
  • In bar charts, add new group or subgroup labels if necessary.
  • In a scatter and line plot, add new data series labels if necessary.

Empty Error

[Error] Cannot access labels of LinePlot 'linePlot', because it is empty.

This error means that you tried to access a value in a chart, but it has no data series, groups, subgroups, etc. yet.

  • In pie charts, add as many slice labels as you need.
  • In bar charts, add as many group or subgroup labels as necessary.
  • In a scatter and line plot, add as many data series labels as you need.

Unknown Item Error

[Error] Access to LinePlot 'linePlot' at label = 'Baseline' is invalid.
        Allowed values for label are here:
        * A
        * B
        * C

This error means that you tried to access a group, subgroup, pie slice, or data series in a chart which does not exist.

  • Check whether you have a typo in the string.
  • Try one of the listed items instead.
  • In pie charts, add a new slice label if necessary.
  • In grid charts, increase the grid size if necessary.
  • In bar charts, add new group or subgroup labels if necessary.
  • In a scatter and line plot, add new data series labels if necessary.

Sources/Contribute

The source code is hosted at GitHub.

Feel free to build new features and fix bugs by creating a pull request. You are also welcome to report any issues and feature suggestions.

License

The MIT License (MIT)

Copyright (c) 2015 Patrick Lühne and Christoph Sterz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.