QLineSeries 继承自QXYSeries,QXYSeries继承自QAbstractSeries
The QLineSeries class presents data in line charts.
A line chart is used to show information as a series of data points connected by straight lines.
QLineSeries类在折线图中显示数据。
折线图用于将信息显示为通过直线连接的一系列数据点。
Header:
#include <QLineSeries>
Instantiated By:LineSeries
Inherits:QXYSeries
Inherited By:QSplineSeries
Reimplemented Public Functions
virtual QAbstractSeries::SeriesType | type() const override |
QLineSeries(QObject *parent = nullptr) | |
virtual |
typedef | |
QList<T> | qFindChildren(const QObject *obj, const QRegExp ®Exp) |
T | qobject_cast(QObject *object) |
T | qobject_cast(const QObject *object) |
Creating a basic line chart is simple:
QLineSeries* series = new QLineSeries();
series->append(0, 6);
series->append(2, 4);
...
chart->addSeries(series);
Member Function Documentation
QLineSeries::QLineSeries(QObject *parent = nullptr)
Constructs an empty series object that is a child of parent. When the series object is added to a QChartView or QChart instance, the ownership is transferred.on构造一个空的系列对象,该对象是父级的子级。 当系列对象添加到QChartView或QChart实例时,所有权就转移了。
[virtual] QLineSeries::~QLineSeries()
Destroys the object. Series added to QChartView or QChart instances are owned by the instances and deleted when the instances are destroyed.销毁对象。 添加到QChartView或QChart实例的系列归实例所有,并在销毁实例时删除。
[override virtual] QAbstractSeries::SeriesType QLineSeries::type() const
Reimplements: QAbstractSeries::type() const.
The QXYSeries class is a base class for line, spline, and scatter series. More...
QXYSeries类是线,样条和散布系列的基类
Header: | #include <QXYSeries> |
Instantiated By: | |
Inherits: | |
Inherited By: |
|
|
Public Functions
virtual | |
void | append(qreal x, qreal y) |
void | append(const QPointF &point) |
void | append(const QList<QPointF> &points) |
const QPointF & | at(int index) const |
QBrush | brush() const |
void | clear() |
virtual QColor | color() const |
int | count() const |
void | insert(int index, const QPointF &point) |
QPen | pen() const |
bool | pointLabelsClipping() const |
QColor | pointLabelsColor() const |
QFont | pointLabelsFont() const |
QString | pointLabelsFormat() const |
bool | pointLabelsVisible() const |
QList<QPointF> | points() const |
QVector<QPointF> | pointsVector() const |
bool | pointsVisible() const |
void | remove(qreal x, qreal y) |
void | remove(const QPointF &point) |
void | remove(int index) |
void | removePoints(int index, int count) |
void | replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
void | replace(const QPointF &oldPoint, const QPointF &newPoint) |
void | replace(int index, qreal newX, qreal newY) |
void | replace(int index, const QPointF &newPoint) |
void | replace(QList<QPointF> points) |
void | replace(QVector<QPointF> points) |
virtual void | setBrush(const QBrush &brush) |
virtual void | setColor(const QColor &color) |
virtual void | setPen(const QPen &pen) |
void | setPointLabelsClipping(bool enabled = true) |
void | setPointLabelsColor(const QColor &color) |
void | setPointLabelsFont(const QFont &font) |
void | setPointLabelsFormat(const QString &format) |
void | setPointLabelsVisible(bool visible = true) |
void | setPointsVisible(bool visible = true) |
QXYSeries & | operator<<(const QPointF &point) |
QXYSeries & | operator<<(const QList<QPointF> &points) |
void | clicked(const QPointF &point) |
void | colorChanged(QColor color) |
void | doubleClicked(const QPointF &point) |
void | hovered(const QPointF &point, bool state) |
void | penChanged(const QPen &pen) |
void | pointAdded(int index) |
void | pointLabelsClippingChanged(bool clipping) |
void | pointLabelsColorChanged(const QColor &color) |
void | pointLabelsFontChanged(const QFont &font) |
void | pointLabelsFormatChanged(const QString &format) |
void | pointLabelsVisibilityChanged(bool visible) |
void | pointRemoved(int index) |
void | pointReplaced(int index) |
void | pointsRemoved(int index, int count) |
void | |
void | pressed(const QPointF &point) |
void | released(const QPointF &point) |
color : QColor
This property holds the color of the series.
This is the line (pen) color in case of QLineSeries or QSplineSeries and the fill (brush) color in case of QScatterSeries or QAreaSeries.
Access functions:
virtual QColor | color() const |
virtual void | setColor(const QColor &color) |
Notifier signal:
void | colorChanged(QColor color) |
This property holds the clipping for data point labels.
This property is true by default. The labels on the edge of the plot area are cut when clipping is enabled.
Access functions:
bool | pointLabelsClipping() const |
void | setPointLabelsClipping(bool enabled = true) |
Notifier signal:
void | pointLabelsClippingChanged(bool clipping) |
See also pointLabelsVisible.
pointLabelsColor : QColor
This property holds the color used for data point labels. By default, the color is the color of the brush defined in theme for labels.
Access functions:
QColor | pointLabelsColor() const |
void | setPointLabelsColor(const QColor &color) |
Notifier signal:
void | pointLabelsColorChanged(const QColor &color) |
See also pointLabelsFormat.
pointLabelsFont : QFont
This property holds the font used for data point labels.
Access functions:
QFont | pointLabelsFont() const |
void | setPointLabelsFont(const QFont &font) |
pointLabelsFormat : QString
This property holds the format used for showing labels with data points.
QXYSeries supports the following format tags:
@xPoint | The x-coordinate of the data point. |
@yPoint | The y-coordinate of the data point. |
For example, the following usage of the format tags would produce labels that display the data point shown inside brackets separated by a comma (x, y):
series->setPointLabelsFormat("(@xPoint, @yPoint)");
By default, the labels' format is set to @xPoint, @yPoint. The labels are shown on the plot area, and the labels on the edge of the plot area are cut. If the points are close to each other, the labels may overlap.
Access functions:
QString | pointLabelsFormat() const |
void | setPointLabelsFormat(const QString &format) |
Notifier signal:
void | pointLabelsFormatChanged(const QString &format) |
See also pointLabelsVisible, pointLabelsFont, and pointLabelsColor.
This property holds the visibility of data point labels.
This property is false by default.
Access functions:
bool | pointLabelsVisible() const |
void | setPointLabelsVisible(bool visible = true) |
Notifier signal:
void | pointLabelsVisibilityChanged(bool visible) |
See also pointLabelsFormat and pointLabelsClipping.
This property holds whether the data points are visible and should be drawn.
Access functions:
bool | pointsVisible() const |
void | setPointsVisible(bool visible = true) |
Member Function Documentation
[signal] void QXYSeries::clicked(const QPointF &point)
This signal is emitted when the user triggers a mouse event by clicking the point point in the chart.
See also pressed(), released(), and doubleClicked().
[signal] void QXYSeries::colorChanged(QColor color)
This signal is emitted when the line (pen) color changes to color.
Note: Notifier signal for property color.
[signal] void QXYSeries::doubleClicked(const QPointF &point)
This signal is emitted when the user double-clicks the data point point in the chart. The point is the point where the first press was triggered.
See also pressed(), released(), and clicked().
[signal] void QXYSeries::hovered(const QPointF &point, bool state)
This signal is emitted when a mouse is hovered over the point point in the chart. When the mouse moves over the point, state turns true, and when the mouse moves away again, it turns false.
[signal] void QXYSeries::penChanged(const QPen &pen)
This signal is emitted when the pen changes to pen.
[signal] void QXYSeries::pointAdded(int index)
This signal is emitted when a point is added at the position specified by index.
See also append() and insert().
[signal] void QXYSeries::pointLabelsClippingChanged(bool clipping)
This signal is emitted when the clipping of the data point labels changes to clipping.
Note: Notifier signal for property pointLabelsClipping.
[signal] void QXYSeries::pointLabelsColorChanged(const QColor &color)
This signal is emitted when the color used for data point labels changes to color.
Note: Notifier signal for property pointLabelsColor.
[signal] void QXYSeries::pointLabelsFontChanged(const QFont &font)
This signal is emitted when the font used for data point labels changes to font.
Note: Notifier signal for property pointLabelsFont.
[signal] void QXYSeries::pointLabelsFormatChanged(const QString &format)
This signal is emitted when the format of data point labels changes to format.
Note: Notifier signal for property pointLabelsFormat.
[signal] void QXYSeries::pointLabelsVisibilityChanged(bool visible)
This signal is emitted when the visibility of the data point labels changes to visible.
Note: Notifier signal for property pointLabelsVisible.
[signal] void QXYSeries::pointRemoved(int index)
This signal is emitted when a point is removed from the position specified by index.
See also remove().
[signal] void QXYSeries::pointReplaced(int index)
This signal is emitted when a point is replaced at the position specified by index.
See also replace().
[signal] void QXYSeries::pointsRemoved(int index, int count)
This signal is emitted when the number of points specified by count is removed starting at the position specified by index.
See also removePoints() and clear().
[signal] void QXYSeries::pointsReplaced()
This signal is emitted when all points are replaced with other points.
See also replace().
[signal] void QXYSeries::pressed(const QPointF &point)
This signal is emitted when the user presses the data point point in the chart and holds down the mouse button.
See also clicked(), released(), and doubleClicked().
[signal] void QXYSeries::released(const QPointF &point)
This signal is emitted when the user releases the mouse press on the data point specified by point.
See also pressed(), clicked(), and doubleClicked().
[virtual] QXYSeries::~QXYSeries()
Deletes the series. Series added to QChart instances are owned by them, and are deleted when the QChart instances are deleted.
void QXYSeries::append(qreal x, qreal y)
Adds the data point with the coordinates x and y to the series.
void QXYSeries::append(const QPointF &point)
This is an overloaded function.
Adds the data point point to the series.
void QXYSeries::append(const QList<QPointF> &points)
This is an overloaded function.
Adds the list of data points specified by points to the series.
const QPointF &QXYSeries::at(int index) const
Returns the data point at the position specified by index in the internal points vector.
QBrush QXYSeries::brush() const
Returns the brush used to fill the data points for the series.
See also setBrush().
void QXYSeries::clear()
Removes all points from the series.
See also pointsRemoved().
int QXYSeries::count() const
Returns the number of data points in a series.
void QXYSeries::insert(int index, const QPointF &point)
Inserts the data point point in the series at the position specified by index.
See also pointAdded().
QPen QXYSeries::pen() const
Returns the pen used to draw the outline of the data points for the series.
See also setPen().
QList<QPointF> QXYSeries::points() const
Returns the points in the series as a list. Use pointsVector() for better performance.
QVector<QPointF> QXYSeries::pointsVector() const
Returns the points in the series as a vector. This is more efficient than calling points().
void QXYSeries::remove(qreal x, qreal y)
Removes the point that has the coordinates x and y from the series.
See also pointRemoved().
void QXYSeries::remove(const QPointF &point)
Removes the data point point from the series.
See also pointRemoved().
void QXYSeries::remove(int index)
Removes the point at the position specified by index from the series.
See also pointRemoved().
void QXYSeries::removePoints(int index, int count)
Removes the number of points specified by count from the series starting at the position specified by index.
See also pointsRemoved().
void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
Replaces the point with the coordinates oldX and oldY with the point with the coordinates newX and newY. Does nothing if the old point does not exist.
See also pointReplaced().
void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
Replaces the point specified by oldPoint with the one specified by newPoint.
See also pointReplaced().
void QXYSeries::replace(int index, qreal newX, qreal newY)
Replaces the point at the position specified by index with the point that has the coordinates newX and newY.
See also pointReplaced().
void QXYSeries::replace(int index, const QPointF &newPoint)
Replaces the point at the position specified by index with the point specified by newPoint.
See also pointReplaced().
void QXYSeries::replace(QList<QPointF> points)
Replaces the current points with the points specified by points.
Note: This is much faster than replacing data points one by one, or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() when the points have been replaced. However, note that using the overload that takes QVector<QPointF> as parameter is faster than using this overload.
See also pointsReplaced().
void QXYSeries::replace(QVector<QPointF> points)
Replaces the current points with the points specified by points.
Note: This is much faster than replacing data points one by one, or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() when the points have been replaced.
See also pointsReplaced().
[virtual] void QXYSeries::setBrush(const QBrush &brush)
Sets the brush used for drawing points on the chart to brush. If the brush is not defined, the brush from the chart theme setting is used.
See also brush() and QChart::setTheme().
[virtual] void QXYSeries::setPen(const QPen &pen)
Sets the pen used for drawing points on the chart to pen. If the pen is not defined, the pen from the chart theme is used.
See also pen() and QChart::setTheme().
QXYSeries &QXYSeries::operator<<(const QPointF &point)
Stream operator for adding the data point point to the series.
See also append().
QXYSeries &QXYSeries::operator<<(const QList<QPointF> &points)
Stream operator for adding the list of data points specified by points to the series.
See also append().
QAbstractSeries Class
The QAbstractSeries class is a base class for all Qt Chart series. More...
Header: | #include <QAbstractSeries> |
Instantiated By: | |
Inherits: | |
Inherited By: | QAbstractBarSeries, QAreaSeries, QBoxPlotSeries, QCandlestickSeries, QPieSeries, and QXYSeries |
Public Types
enum | SeriesType { SeriesTypeLine, SeriesTypeArea, SeriesTypeBar, SeriesTypeStackedBar, ..., SeriesTypeCandlestick } |
Properties
- 1 property inherited from QObject
Public Functions
virtual | |
bool | attachAxis(QAbstractAxis *axis) |
QList<QAbstractAxis *> | |
QChart * | chart() const |
bool | detachAxis(QAbstractAxis *axis) |
void | hide() |
bool | isVisible() const |
QString | name() const |
qreal | opacity() const |
void | setName(const QString &name) |
void | setOpacity(qreal opacity) |
void | setUseOpenGL(bool enable = true) |
void | setVisible(bool visible = true) |
void | show() |
virtual QAbstractSeries::SeriesType | type() const = 0 |
bool | useOpenGL() const |
- 30 public functions inherited from QObject
Signals
void | |
void | |
void | |
void |
- 2 signals inherited from QObject
Related Non-Members
typedef | |
QList<T> | qFindChildren(const QObject *obj, const QRegExp ®Exp) |
T | qobject_cast(QObject *object) |
T | qobject_cast(const QObject *object) |
Macros
Q_CLASSINFO(Name, Value) | |
Q_DISABLE_COPY(Class) | |
Q_DISABLE_COPY_MOVE(Class) | |
Q_DISABLE_MOVE(Class) | |
Q_ENUM(...) | |
Q_ENUM_NS(...) | |
Q_FLAG(...) | |
Q_FLAG_NS(...) | |
Q_INTERFACES(...) | |
Q_PROPERTY(...) | |
Q_SET_OBJECT_NAME(Object) | |
Additional Inherited Members
- 1 public slot inherited from QObject
- 9 static public members inherited from QObject
- 9 protected functions inherited from QObject
Detailed Description
Usually, the series type specific inherited classes are used instead of the base class.
See also QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries, QHorizontalBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries, and QPieSeries.
Member Type Documentation
enum QAbstractSeries::SeriesType
This enum describes the type of the series.
Constant | Value | Description |
QAbstractSeries::SeriesTypeLine | 0 | A line chart. |
QAbstractSeries::SeriesTypeArea | 1 | An area chart. |
QAbstractSeries::SeriesTypeBar | 2 | A vertical bar chart. |
QAbstractSeries::SeriesTypeStackedBar | 3 | A vertical stacked bar chart. |
QAbstractSeries::SeriesTypePercentBar | 4 | A vertical percent bar chart. |
QAbstractSeries::SeriesTypePie | 5 | A pie chart. |
QAbstractSeries::SeriesTypeScatter | 6 | A scatter chart. |
QAbstractSeries::SeriesTypeSpline | 7 | A spline chart. |
QAbstractSeries::SeriesTypeHorizontalBar | 8 | A horizontal bar chart. |
QAbstractSeries::SeriesTypeHorizontalStackedBar | 9 | A horizontal stacked bar chart. |
QAbstractSeries::SeriesTypeHorizontalPercentBar | 10 | A horizontal percent bar chart. |
QAbstractSeries::SeriesTypeBoxPlot | 11 | A box plot chart. |
QAbstractSeries::SeriesTypeCandlestick | 12 | A candlestick chart. |
Property Documentation
name : QString
This property holds the name of the series.
The name is displayed in the legend for the series and it supports HTML formatting.
Access functions:
QString | name() const |
void | setName(const QString &name) |
Notifier signal:
void |
opacity : qreal
This property holds the opacity of the series.
By default, the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
Access functions:
qreal | opacity() const |
void | setOpacity(qreal opacity) |
Notifier signal:
void |
type : const SeriesType
This property holds the type of the series.
Access functions:
virtual QAbstractSeries::SeriesType | type() const = 0 |
useOpenGL : bool
Specifies whether or not drawing the series is accelerated by using OpenGL.
Acceleration using OpenGL is supported only for QLineSeries and QScatterSeries. A line series used as an edge series for QAreaSeries cannot use OpenGL acceleration. When a chart contains any series that are drawn with OpenGL, a transparent QOpenGLWidget is created on top of the chart plot area. The accelerated series are not drawn on the underlying QGraphicsView, but are instead drawn on the created QOpenGLWidget.
Performance gained from using OpenGL to accelerate series drawing depends on the underlying hardware, but in most cases it is significant. For example, on a standard desktop computer, enabling OpenGL acceleration for a series typically allows rendering at least a hundred times more points without reduction on the frame rate. Chart size also has less effect on the frame rate.
The OpenGL acceleration of series drawing is meant for use cases that need fast drawing of large numbers of points. It is optimized for efficiency, and therefore the series using it lack support for many features available to non-accelerated series:
- Series animations are not supported for accelerated series.
- Point labels are not supported for accelerated series.
- Pen styles and marker shapes are ignored for accelerated series. Only solid lines and plain scatter dots are supported. The scatter dots may be circular or rectangular, depending on the underlying graphics hardware and drivers.
- Polar charts do not support accelerated series.
- Enabling chart drop shadow or using transparent chart background color is not recommended when using accelerated series, as that can slow the frame rate down significantly.
These additional restrictions stem from the fact that the accelerated series is drawn on a separate widget on top of the chart:
- If you draw any graphics items on top of a chart containing an accelerated series, the accelerated series is drawn over those items.
- To enable QOpenGLWidget to be partially transparent, it needs to be stacked on top of all other widgets. This means you cannot have other widgets partially covering the chart when using accelerated series.
- Accelerated series are not supported for use cases where the graphics scene has more than one graphics view attached to it.
- Accelerated series are not supported for use cases where the chart has non-default geometry. For example, adding transforms to the graphics view causes the accelerated series to be drawn in an incorrect position related to the chart.
The default value is false.
Access functions:
bool | useOpenGL() const |
void | setUseOpenGL(bool enable = true) |
Notifier signal:
void |
visible : bool
This property holds whether the series is visible or not.
By default, true.
Access functions:
bool | isVisible() const |
void | setVisible(bool visible = true) |
Notifier signal:
void |
Member Function Documentation
[signal] void QAbstractSeries::nameChanged()
This signal is emitted when the series name changes.
Note: Notifier signal for property name.
[signal] void QAbstractSeries::opacityChanged()
This signal is emitted when the opacity of the series changes.
Note: Notifier signal for property opacity.
[signal] void QAbstractSeries::useOpenGLChanged()
This signal is emitted when accelerating the drawing of the series by using OpenGL is enabled or disabled.
Note: Notifier signal for property useOpenGL.
[signal] void QAbstractSeries::visibleChanged()
This signal is emitted when the series visibility changes.
Note: Notifier signal for property visible.
[virtual] QAbstractSeries::~QAbstractSeries()
Virtual destructor for the chart series.
bool QAbstractSeries::attachAxis(QAbstractAxis *axis)
Attaches the axis specified by axis to the series.
Returns true if the axis was attached successfully, false otherwise.
Note: If multiple axes of the same orientation are attached to the same series, they will have the same minimum and maximum values.
See also QChart::addAxis() and QChart::createDefaultAxes().
QList<QAbstractAxis *> QAbstractSeries::attachedAxes()
Returns the list of axes attached to the series. Usually, an x-axis and a y-axis are attached to a series, except for QPieSeries, which does not have any axes attached.
See also attachAxis() and detachAxis().
QChart *QAbstractSeries::chart() const
Returns the chart that the series belongs to.
Set automatically when the series is added to the chart, and unset when the series is removed from the chart.
bool QAbstractSeries::detachAxis(QAbstractAxis *axis)
Detaches the axis specified by axis from the series.
Returns true if the axis was detached successfully, false otherwise.
See also QChart::removeAxis().
void QAbstractSeries::hide()
Sets the visibility of the series to false.
See also setVisible() and isVisible().
void QAbstractSeries::show()
Sets the visibility of the series to true.
See also setVisible() and isVisible().