KQuickCharts

LineChartControl.qml
1/*
2 * This file is part of KQuickCharts
3 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8import QtQuick
9import QtQuick.Controls
10
11import org.kde.quickcharts as Charts
12import org.kde.quickcharts.controls
13
14/**
15 * A line chart with legend, grid and axis labels.
16 */
17Control {
18
19 property alias valueSources: lineChart.valueSources
20 property alias names: nameSource.array
21 property alias color: colorSource.baseColor
22
23 property alias lineWidth: lineChart.lineWidth
24 property alias fillOpacity: lineChart.fillOpacity
25 property alias stacked: lineChart.stacked
26
27 property alias chart: lineChart
28 property alias legend: legend
29 property alias xLabels: xAxisLabels
30 property alias yLabels: yAxisLabels
31
32 property alias verticalLinesVisible: verticalLines.visible
33 property alias horizontalLinesVisible: horizontalLines.visible
34
35 property alias xRange: lineChart.xRange
36 property alias yRange: lineChart.yRange
37
38 property alias xAxisSource: xAxisLabels.source
39 property alias yAxisSource: yAxisLabels.source
40
41 property alias pointDelegate: lineChart.pointDelegate
42
43 background: Rectangle { color: Theme.backgroundColor }
44
45 contentItem: Item {
46 anchors.fill: parent;
47
48 GridLines {
49 id: horizontalLines
50
51 anchors.fill: lineChart
52
53 chart: lineChart
54
55 major.frequency: 2
56 major.lineWidth: 2
57 major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
58
59 minor.frequency: 1
60 minor.lineWidth: 1
61 minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
62 }
63
64 GridLines {
65 id: verticalLines
66
67 anchors.fill: lineChart
68
69 chart: lineChart
70
71 direction: GridLines.Vertical;
72
73 major.count: 1
74 major.lineWidth: 2
75 major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
76
77 minor.count: 3
78 minor.lineWidth: 1
79 minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
80 }
81
83 id: yAxisLabels
84
85 anchors {
86 left: parent.left
87 top: parent.top
88 bottom: xAxisLabels.top
89 }
90
91 direction: AxisLabels.VerticalBottomTop
92 delegate: Label { text: AxisLabels.label }
93 source: Charts.ChartAxisSource { chart: lineChart; axis: Charts.ChartAxisSource.YAxis; itemCount: 5 }
94 }
95
97 id: xAxisLabels
98
99 anchors {
100 left: yAxisLabels.visible ? yAxisLabels.right : parent.left
101 right: parent.right
102 bottom: legend.top
103 }
104
105 delegate: Label { text: AxisLabels.label }
106 source: Charts.ChartAxisSource { chart: lineChart; axis: Charts.ChartAxisSource.XAxis; itemCount: 5 }
107 }
108
109 Legend {
110 id: legend
111
112 anchors {
113 left: yAxisLabels.visible ? yAxisLabels.right : parent.left
114 right: parent.right
115 bottom: parent.bottom
116 bottomMargin: Theme.smallSpacing
117 }
118
119 chart: lineChart
120 }
121
122 Charts.LineChart {
123 id: lineChart
124 anchors {
125 top: parent.top
126 left: yAxisLabels.visible ? yAxisLabels.right : parent.left
127 right: parent.right
128 bottom: xAxisLabels.visible ? xAxisLabels.top : legend.top
129 }
130
131 xRange.automatic: true
132 yRange.automatic: true
133
134 colorSource: Charts.ColorGradientSource { id: colorSource; baseColor: Theme.highlightColor; itemCount: lineChart.valueSources.length }
135 nameSource: Charts.ArraySource { id: nameSource; array: ["1", "2", "3", "4", "5"] }
136 }
137 }
138}
An item that uses a delegate to place axis labels on a chart.
Definition AxisLabels.h:49
An item that renders a set of lines to make a grid for a chart.
Definition GridLines.h:63
A pre-made legend control that displays a legend for charts.
Definition Legend.qml:15
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:57 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.