Qt 5.7 | Qt Charts | QML Types | ChartView QML Type

Qt 5.7.1 Reference Documentation

# ChartView QML Type

Chart element. More...

Import Statement: | import QtCharts 2.1

- List of all members, including inherited members

## Properties

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

## Signals

- seriesAdded(AbstractSeries series)
- seriesRemoved(AbstractSeries series)

## Methods

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

## Detailed Description

ChartView element is the parent that is responsible for showing different chart series types.

The following QML 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 : Animation

Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, ChartView.SeriesAnimations or ChartView.AllAnimations.

axes : list<AbstractAxis>

The axes of the ChartView.

backgroundColor : color

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

See also ChartView::theme.

backgroundRoundness : real

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

count : int

The count of series added to the chart.

dropShadowEnabled : bool

The chart's border drop shadow. Set to true to enable drop shadow.

legend : Legend

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

locale : locale

Sets the locale used to format various chart labels when localizeNumbers is `true`. This also determines the locale used to format DateTimeAxis labels regardless of localizeNumbers property. Defaults to application default locale at the time the chart is constructed.

This QML property was introduced in QtCharts 2.0.

See also localizeNumbers.

localizeNumbers : bool

When `true`, all generated numbers appearing in various series and axis labels will be localized using the default QLocale of the application, which defaults to the system locale. When `false`, the "C" locale is always used. Defaults to `false`.

This QML property was introduced in QtCharts 2.0.

See also locale.

margins : Margins

The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins area of ChartView is used for drawing title, axes and legend.

plotArea : rect

The area on the ChartView that is used for drawing series. This is the ChartView rect without the margins.

See also ChartView::margins.

plotAreaColor : color

The color of the background of the chart's plot area. By default plot area background uses chart's background color.

See also ChartView::backgroundColor.

theme : Theme

Theme defines the visual appearance of the chart, including for example colors, fonts, line widths and chart background.

title : string

The title of the chart, shown on top of the chart.

See also ChartView::titleColor.

titleColor : color

The color of the title text.

titleFont : Font

The title font of the chart.

See the Qt documentation for more details of Font.

## Signal Documentation

seriesAdded(AbstractSeries series)

The series has been added to the chart.

seriesRemoved(AbstractSeries series)

The series has been removed from the chart. Please note that series is no longer a valid object after the signal handler has completed.

## Method Documentation

Axis axisX(AbstractSeries series)

The x-axis of the series.

Axis axisY(AbstractSeries series)

The y-axis of the series.

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

Creates a series object of type to the chart with name name, optional axis axisX and optional axis axisY. For example:

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

isZoomed()

Returns true if any series has a zoomed domain.

point mapToPosition(point value, AbstractSeries series)

Returns the position on the chart that corresponds to the value in the series domain.

point mapToValue(point position, AbstractSeries series)

Returns the value in the series domain that corresponds to the position relative to the chart.

removeAllSeries()

Removes all series from the chart. All the series objects are also destroyed.

removeSeries(AbstractSeries series)

Removes the series from the chart. The series object is also destroyed.

scrollDown(real pixels)

Scrolls down by pixels. This is a convenience function that suits for example for key navigation.

scrollLeft(real pixels)

Scrolls to left by pixels. This is a convenience function that suits for example for key navigation.

scrollRight(real pixels)

Scrolls to right by pixels. This is a convenience function that suits for example for key navigation.

scrollUp(real pixels)

Scrolls up by pixels. This is a convenience function that suits for example for key navigation.

AbstractSeries series(string name)

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

AbstractSeries series(int index)

Returns the series with index on the chart. This allows you to loop through the series of a chart together with the count property of the chart.

setAxisX(AbstractAxis axis, AbstractSeries series)

Set the x-axis of the series.

setAxisY(AbstractAxis axis, AbstractSeries series)

Set the y-axis of the series.

zoom(real factor)

Zooms in by factor on the center of the chart.

A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.

zoomIn(rect rectangle)

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

Note: This is not supported for polar charts.

zoomIn()

Zooms in the view by a factor of two.

zoomOut()

Zooms out the view by a factor of two.

zoomReset()

Resets the series domains to what they were before any zoom method was called. Note that this will also reset any scrolls and explicit axis range settings done between the first zoom operation and calling this method. If no zoom operation has been done, this method does nothing.