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 property alias highlightEnabled: legend.highlightEnabled
44
45 background: Rectangle { color: Theme.backgroundColor }
46
47 contentItem: Item {
48 anchors.fill: parent;
49
50 GridLines {
51 id: horizontalLines
52
53 anchors.fill: lineChart
54
55 chart: lineChart
56
57 major.frequency: 2
58 major.lineWidth: 2
59 major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
60
61 minor.frequency: 1
62 minor.lineWidth: 1
63 minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
64 }
65
66 GridLines {
67 id: verticalLines
68
69 anchors.fill: lineChart
70
71 chart: lineChart
72
73 direction: GridLines.Vertical;
74
75 major.count: 1
76 major.lineWidth: 2
77 major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
78
79 minor.count: 3
80 minor.lineWidth: 1
81 minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
82 }
83
85 id: yAxisLabels
86
87 anchors {
88 left: parent.left
89 top: parent.top
90 bottom: xAxisLabels.top
91 }
92
93 direction: AxisLabels.VerticalBottomTop
94 delegate: Label { text: AxisLabels.label }
95 source: Charts.ChartAxisSource { chart: lineChart; axis: Charts.ChartAxisSource.YAxis; itemCount: 5 }
96 }
97
99 id: xAxisLabels
100
101 anchors {
102 left: yAxisLabels.visible ? yAxisLabels.right : parent.left
103 right: parent.right
104 bottom: legend.top
105 }
106
107 delegate: Label { text: AxisLabels.label }
108 source: Charts.ChartAxisSource { chart: lineChart; axis: Charts.ChartAxisSource.XAxis; itemCount: 5 }
109 }
110
111 Legend {
112 id: legend
113
114 anchors {
115 left: yAxisLabels.visible ? yAxisLabels.right : parent.left
116 right: parent.right
117 bottom: parent.bottom
118 bottomMargin: Theme.smallSpacing
119 }
120
121 chart: lineChart
122 }
123
124 Charts.LineChart {
125 id: lineChart
126 anchors {
127 top: parent.top
128 left: yAxisLabels.visible ? yAxisLabels.right : parent.left
129 right: parent.right
130 bottom: xAxisLabels.visible ? xAxisLabels.top : legend.top
131 }
132
133 xRange.automatic: true
134 yRange.automatic: true
135
136 colorSource: Charts.ColorGradientSource { id: colorSource; baseColor: Theme.highlightColor; itemCount: lineChart.valueSources.length }
137 nameSource: Charts.ArraySource { id: nameSource; array: ["1", "2", "3", "4", "5"] }
138
139 highlight: legend.highlightedIndex
140 }
141 }
142}
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
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 Fri May 17 2024 11:54:36 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.