Qt 5.13 | Qt Charts | QML Types | ChartView QML Type

Qt Charts | Commercial or GPLv3

# ChartView QML Type

Manages the graphical representation of the chart's series, legends, and axes. More...

Import Statement: | import QtCharts 2.13
Inherited By: | PolarChartView

- List of all members, including inherited members

## Properties

- animationDuration : int
- animationEasingCurve : easing
- animationOptions : enumeration
- axes : list<AbstractAxis>
- backgroundColor : color
- backgroundRoundness : real
- count : int
- dropShadowEnabled : bool
- legend : Legend
- locale : locale
- localizeNumbers : bool
- margins : Margins
- plotArea : rect
- plotAreaColor : color
- theme : enumeration
- title : string
- titleColor : color
- titleFont : font

## Signals

- seriesAdded(series)
- seriesRemoved(series)

## Methods

- Axis axisX(series)
- Axis axisY(series)
- AbstractSeries createSeries(type, string name, AbstractAxis axisX, AbstractAxis axisY)
- isZoomed()
- point mapToPosition(value, AbstractSeries series)
- point mapToValue(position, AbstractSeries series)
- removeAllSeries()
- removeSeries(series)
- scrollDown(pixels)
- scrollLeft(pixels)
- scrollRight(pixels)
- scrollUp(pixels)
- AbstractSeries series(name)
- AbstractSeries series(index)
- setAxisX(axis, AbstractSeries series)
- setAxisY(axis, AbstractSeries series)
- zoom(factor)
- zoomIn(rectangle)
- zoomIn()
- zoomOut()
- zoomReset()

## Detailed Description

The ChartView type displays different series types as charts.

The following QML code shows how to create a simple chart with one pie series:

      import QtQuick 2.0
      import QtCharts 2.0

      ChartView {
          width: 400
          height: 300
          theme: ChartView.ChartThemeBrownSand
          antialiasing: true

          PieSeries {
              id: pieSeries
              PieSlice { label: "eaten"; value: 94.9 }
              PieSlice { label: "not yet eaten"; value: 5.1 }
          }
      }

## Property Documentation

animationDuration : int

The duration of the animation for the chart.

animationEasingCurve : easing

The easing curve of the animation for the chart.

animationOptions : enumeration

The animations enabled in the chart:

Constant | Description
--- | ---
`ChartView.NoAnimation` | Animation is disabled in the chart. This is the default value.
`ChartView.GridAxisAnimations` | Grid axis animation is enabled in the chart.
`ChartView.SeriesAnimations` | Series animation is enabled in the chart.
`ChartView.AllAnimations` | All animation types are enabled in the chart.

axes : list<AbstractAxis>

The axes of the chart.

backgroundColor : color

The color of the chart's background. By default, the background color is specified by the chart theme.

See also theme.

backgroundRoundness : real

The diameter of the rounding circle at the corners of the chart background.

count : int

The number of series added to the chart.

dropShadowEnabled : bool

Whether the background drop shadow effect is enabled.

If set to `true`, the background drop shadow effect is enabled. If set to `false`, it is disabled.

legend : Legend

The legend of the chart. The legend lists all the series, pie slices, and bar sets added to the chart.

locale : locale

The locale used to format various chart labels.

Labels are localized only when localizeNumbers is `true`, except for DateTimeAxis labels, which always use the QLocale set with this property.

Defaults to the application default locale at the time when the chart is constructed.

This property was introduced in QtCharts 2.0.

See also localizeNumbers.

localizeNumbers : bool

Whether numbers are localized.

When `true`, all generated numbers appearing in various series and axis labels will be localized using the QLocale set with the locale property. When `false`, the C locale is always used. Defaults to `false`.

Note: This property does not affect DateTimeAxis labels, which always use the QLocale set with the locale property.

This property was introduced in QtCharts 2.0.

See also locale.

margins : Margins

The minimum margins allowed between the edge of the chart rectangle and the plot area. The margins are used for drawing the title, axes, and legend.

plotArea : rect

The rectangle within which the chart is drawn.

The plot area does not include the area defined by margins. By default this will resize if inside a ChartView. If an explicit rectangle is set for the plot area then it will respect this, to revert back to the default behavior, then setting it to `Qt.rect(0, 0, 0, 0)` will achieve this.

See also margins.

plotAreaColor : color

The color of the background of the chart's plot area. By default, the plot area background uses the chart's background color, which is specified by the chart theme.

See also backgroundColor and theme.

theme : enumeration

The theme used by the chart.

A theme is a built-in collection of UI style related settings applied to all the visual elements of a chart, such as colors, pens, brushes, and fonts of series, as well as axes, title, and legend. The Qml Oscilloscope example illustrates how to set a theme.

Note: Changing the theme will overwrite all customizations previously applied to the series.

The following values are supported:

Constant | Description
--- | ---
`ChartView.ChartThemeLight` | The light theme, which is the default theme.
`ChartView.ChartThemeBlueCerulean` | The cerulean blue theme.
`ChartView.ChartThemeDark` | The dark theme.
`ChartView.ChartThemeBrownSand` | The sand brown theme.
`ChartView.ChartThemeBlueNcs` | The natural color system (NCS) blue theme.
`ChartView.ChartThemeHighContrast` | The high contrast theme.
`ChartView.ChartThemeBlueIcy` | The icy blue theme.
`ChartView.ChartThemeQt` | The Qt theme.

title : string

The title is shown as a headline on top of the chart. Chart titles support HTML formatting.

See also titleColor.

titleColor : color

The color of the title text.

titleFont : font

The title font of the chart.

For more information, see font.

## Signal Documentation

seriesAdded(series)

This signal is emitted when the series series is added to the chart.

seriesRemoved(series)

This signal is emitted when the series series is removed from the chart. The series object becomes invalid when the signal handler completes.

## Method Documentation

Axis axisX(series)

The x-axis of the series.

See also setAxisX().

Axis axisY(series)

The y-axis of the series.

See also setAxisY().

AbstractSeries createSeries(type, string name, AbstractAxis axisX, AbstractAxis axisY)

Adds a series of the type type to the chart with the name name and, optionally, the axes axisX and axisY. For example:

      // lineSeries is a LineSeries object that has already been added to the ChartView; re-use its axes
      var myAxisX = chartView.axisX(lineSeries);
      var myAxisY = chartView.axisY(lineSeries);
      var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);

The following enumeration values can be used as values of type:

Constant | Description
--- | ---
`ChartView.SeriesTypeLine` | A line series.
`ChartView.SeriesTypeArea` | An area series.
`ChartView.SeriesTypeBar` | A bar series.
`ChartView.SeriesTypeStackedBar` | A stacked bar series.
`ChartView.SeriesTypePercentBar` | A percent bar series.
`ChartView.SeriesTypeBoxPlot` | A box plot series.
`ChartView.SeriesTypeCandlestick` | A candlestick series.
`ChartView.SeriesTypePie` | A pie series.
`ChartView.SeriesTypeScatter` | A scatter series.
`ChartView.SeriesTypeSpline` | A spline series.
`ChartView.SeriesTypeHorizontalBar` | A horizontal bar series.
`ChartView.SeriesTypeHorizontalStackedBar` | A horizontal stacked bar series.
`ChartView.SeriesTypeHorizontalPercentBar` | A horizontal percent bar series.

isZoomed()

Returns `true` if any series has a zoomed domain.

point mapToPosition(value, AbstractSeries series)

Returns the position in the chart of the value value in the series series.

point mapToValue(position, AbstractSeries series)

Returns the value in the series series located at the position position in the chart.

removeAllSeries()

Removes all series from the chart and permanently deletes all the series objects.

removeSeries(series)

Removes the series series from the chart and permanently deletes the series object.

scrollDown(pixels)

Scrolls down by the number of pixels specified by pixels. This is a convenience method suitable for key navigation, for example.

scrollLeft(pixels)

Scrolls to left by the number of pixels specified by pixels. This is a convenience method suitable for key navigation, for example.

scrollRight(pixels)

Scrolls to right by by the number of pixels specified by pixels. This is a convenience method suitable for key navigation, for example.

scrollUp(pixels)

Scrolls up by the number of pixels specified by pixels. This is a convenience method suitable for key navigation, for example.

AbstractSeries series(name)

Returns the first series in the chart with the name name. If there is no series with that name, returns null.

AbstractSeries series(index)

Returns the series with the index index on the chart. Together with the count property of the chart, this enables looping through the series of a chart.

See also count.

setAxisX(axis, AbstractSeries series)

Sets the x-axis of the series.

See also axisX().

setAxisY(axis, AbstractSeries series)

Sets the y-axis of the series.

See also axisY().

zoom(factor)

Zooms into the chart by the custom factor factor.

A factor over 1.0 zooms into the view in and a factor between 0.0 and 1.0 zooms out of it.

zoomIn(rectangle)

Zooms into the view to a maximum level at which the rectangle rectangle is still fully visible.

Note: This is not supported for polar charts.

zoomIn()

Zooms into the view by a factor of two.

zoomOut()

Zooms out of the view by a factor of two.

zoomReset()

Resets the series domains to what they were before any zoom method was called.

Note: This will also reset scrolling and explicit axis range settings specified between the first zoom operation and calling this method. If no zoom operation has been performed, this method does nothing.