Introduction to Qt Charts

1. Icon type Charts classification

Charts are created by using an instance of the Series class and adding it to a QChart or ChartView instance.

The Qt chart module provides the following chart types:

1. Line charts and spline charts

Line and spline charts display data as a series of data points connected by straight lines. In a line chart, the data points are connected by straight lines, whereas in a spline chart, they are connected by splines. Splines are drawn using QPainterPath . Line charts are implemented using the QLineSeries class. Spline plots are implemented using the QSplineSeries class, which inherits from QLineSeries .
Insert image description here

2. Area charts and scatter charts

An area chart represents data as an area bounded by two lines, while a scatter chart displays data as a collection of points.
Area charts are implemented using the QAreaSeries class. By default, the x-axis is used as one bound and the QLineSeries is used as the other bound. However, it is possible to use QLineSeries as both boundaries. Scatter plots are implemented using the QScatterSeries class.

Insert image description here

3. Bar chart

Bar charts display data as horizontal or vertical bars grouped by categories. The QBarSet class represents a set of bars in a bar chart. The QAbstractBarSeries class is the abstract parent class of all bar series classes, and the series type determines how the data is displayed. The QBarSeries class displays data as vertical bars grouped by category. Similarly, the QHorizontalBarSeries class displays data as horizontal bars. The QStackedBarSeries class displays a series of data as vertically stacked bars, one bar for each category. The corresponding horizontal class and type is QHorizontalStackedBarSeries . The QPercentBarSeries class represents a series of categorical data as a percentage of each category. The corresponding horizontal class and type is QHorizontalPercentBarSeries .
Insert image description here
Insert image description here

4. Pie chart

Pie charts display data as a pie composed of pie slices. Pie charts are implemented using the QPieSeries class, and pie chart slices are added using the QPieSlice class.

Insert image description here

5. Error Bar Plot

Error bars display data in quartiles, with whiskers indicating the variability of values. Items in a box chart series are grouped into categories, similar to the set of bars in a bar chart series. For each box and whisker item, the lower extreme value, lower quartile, median, upper quartile, and upper extreme value are specified. Implement box and whisker plots by using the QBoxPlotSeries and QBoxSet classes.
Insert image description here

6. Candlestick chart

A candlestick chart displays a series of data in the form of candlesticks.

Candlestick charts are implemented by using QCandlestickSeries and QCandlestickSet classes.
Insert image description here

7.Polar coordinate chart

Polar plots display data as a circular graph, where the placement of the data is based on the angle and distance from the center polar coordinate of the graph.

The QPolarChart class is a specialization of the QChart class. It supports lines, splines, areas, and scatter sequences, as well as all axis types they support. This axis can be used as a radial axis or an angular axis.
Insert image description here

2. Classification of Axes Types

Qt charts support the following axis types:

  • Value axis: Numeric axis, the axis that adds actual values ​​to the chart. It is implemented using QValueAxis class.
  • Category axis: Category coordinate axis, implemented using the QCategoryAxis class. It has named ranges and adjustable range width.
  • Bar category axis: Bar chart category axis, similar to the category axis, but the range width is the same for all ranges. Use the QBarCategoryAxis class to implement the bar category axis.
  • Date-time axis: Date-time coordinate axis, which adds date and time to the axis of the chart. It is implemented using QDateTimeAxis class.
  • Logarithmic value axis: Logarithmic value axis, logarithmic scale is added to the axis of the chart. A logarithmic scale is a non-linear scale based on orders of magnitude, so each tick mark on the axis is the previous tick mark multiplied by a value. Use the QLogValueAxis class to implement the logarithmic axis.

Axis can be set up to show lines with tick marks, grid lines, and shading. Values ​​on the axis are plotted at the location of the tick marks. All axis types are specializations of the QAbstractAxis class. Multiple axes can be defined for a chart. Axes can be placed below, above, left, or right of the chart. Furthermore, the axes can be of different types. However, mixing axis types that would result in different domains, such as specifying QValueAxis and QLogValueAxis in the same direction, is not supported .

3. Legend

The legend is a graphics object that displays the chart legend. Legend objects cannot be created or deleted, but they can be referenced through the QChart class. QChart updates the legend state when the series changes . The legend can be below or above the chart, or to the left or right of the chart. By default, the legend is attached to the chart view, but can be detached to a separate graph item, which can be moved freely. You can hide individual markers from the legend or the entire legend. Legend markers can be modified by using the QLegendMarker base class and subclasses for each series type: QAreaLegendMarker , QBarLegendMarker , QBoxPlotLegendMarker , QCandlestickLegendMarker , and QXYLegendMarker .

4. Interaction of charts

  1. Interact with charts End users can interact with charts by dynamically adding values ​​to the chart, drilling into data, zooming in and out of the chart, scrolling through the chart, clicking on items in the chart, or hovering over the chart.
  2. Dynamic Graph Data allows you to dynamically add data to a chart and have the chart view automatically scroll to display new data.
  3. Detailed data display, drill effect can be implemented as bar chart or pie chart. When the user selects an item in the chart, a more detailed view of the item is displayed.
  4. Zoom and scroll, users can zoom and scroll using the keyboard. They can use the arrow keys to scroll the chart and the plus and minus keys to zoom in or out. Additionally, the QRubberBand can be used to select an area to zoom in on.
  5. Click and Hover connects the slot to a signal that is emitted when the end user clicks or hovers over an item in the chart. This enables adding elements to the diagram, such as labels.

5. Chart style theme

Qt charts have the following predefined themes:

  • Light theme, which is the default theme:Highlight theme
  • Cerulean blue theme: blue theme
  • Dark theme: dark theme
  • Sand brown theme:Sand brown theme
  • Natural color system (NCS) blue theme:Natural blue theme
  • High contrast theme: high contrast theme
  • Icy blue theme: ice blue theme
  • Qt theme: Qt type theme

Themes can be customized by changing colors, pens, brushes, and fonts. New themes can be added by modifying the Qt chart source code.

  1. ChartThemeLight
    Insert image description here

  2. ChartThemeBlueCerulean
    Insert image description here

  3. ChartThemeDark

    Insert image description here

  4. ChartThemeBrownSand

Insert image description here

  1. ChartThemeBlueNcs

    Insert image description here

  2. ChartThemeHighContrast

    Insert image description here

  3. ChartThemeBlueIcy

    Insert image description here

  4. QT

    Insert image description here

content value illustrate
QChart::NoAnimation 0x0 Animation is disabled in the chart. It's the default value.
QChart::GridAxisAnimations 0x1 Enable grid axis animation in the chart.
QChart::SeriesAnimations 0x2 Series animation is enabled in the chart.
QChart::AllAnimations 0x3 All animation types are enabled in the chart.

Guess you like

Origin blog.csdn.net/qq_30150579/article/details/133066556