Warning, /frameworks/kquickcharts/examples/charts/BarChart.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * This file is part of KQuickCharts
0003 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0004 *
0005 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007
0008 import QtQuick
0009 import QtQuick.Controls
0010 import QtQuick.Layouts
0011
0012 import org.kde.kirigami as Kirigami
0013 import org.kde.kquickcontrols
0014
0015 import org.kde.quickcharts as Charts
0016 import org.kde.quickcharts.controls as ChartsControls
0017
0018 Kirigami.Page {
0019 title: "Bar Chart"
0020
0021 ListModel {
0022 id: barModel;
0023 dynamicRoles: true;
0024
0025 Component.onCompleted: {
0026 append({label: "Item 1", value1: 0, value2: 15, value3: 20})
0027 append({label: "Item 2", value1: 10, value2: 25, value3: 25})
0028 append({label: "Item 3", value1: 15, value2: 20, value3: 30})
0029 append({label: "Item 4", value1: 10, value2: 10, value3: 35})
0030 append({label: "Item 5", value1: 20, value2: 5, value3: 40})
0031 }
0032 }
0033
0034 ColumnLayout {
0035 anchors.fill: parent
0036 anchors.margins: Kirigami.Units.largeSpacing
0037 spacing: Kirigami.Units.largeSpacing
0038
0039 Kirigami.AbstractCard {
0040 Layout.fillHeight: false
0041 Layout.preferredHeight: 400
0042 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
0043
0044 ChartsControls.GridLines {
0045 anchors.fill: barChart
0046
0047 chart: barChart
0048
0049 major.visible: false
0050
0051 minor.count: 4
0052 minor.lineWidth: 1
0053 minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
0054 }
0055
0056 ChartsControls.GridLines {
0057 anchors.fill: barChart
0058
0059 chart: barChart
0060
0061 direction: ChartsControls.GridLines.Vertical;
0062
0063 major.count: 1
0064 major.lineWidth: 2
0065 major.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
0066
0067 minor.count: 3
0068 minor.lineWidth: 1
0069 minor.color: Qt.rgba(0.8, 0.8, 0.8, 1.0)
0070 }
0071
0072 ChartsControls.AxisLabels {
0073 id: yAxisLabels
0074
0075 anchors {
0076 left: parent.left
0077 top: parent.top
0078 bottom: xAxisLabels.top
0079 }
0080
0081 direction: ChartsControls.AxisLabels.VerticalBottomTop
0082 delegate: Label { text: ChartsControls.AxisLabels.label }
0083 source: Charts.ChartAxisSource { chart: barChart; axis: Charts.ChartAxisSource.YAxis; itemCount: 5 }
0084 }
0085
0086 ChartsControls.AxisLabels {
0087 id: xAxisLabels
0088
0089 anchors {
0090 left: yAxisLabels.right
0091 right: parent.right
0092 bottom: legend.top
0093 }
0094
0095 delegate: Label { text: ChartsControls.AxisLabels.label }
0096 source: Charts.ModelSource { model: barModel; roleName: "label" }
0097 }
0098
0099 ChartsControls.Legend {
0100 id: legend
0101
0102 anchors {
0103 left: yAxisLabels.right
0104 right: parent.right
0105 bottom: parent.bottom
0106 bottomMargin: Kirigami.Units.smallSpacing
0107 }
0108
0109 chart: barChart
0110 }
0111
0112 Charts.BarChart {
0113 id: barChart
0114 anchors {
0115 top: parent.top
0116 left: yAxisLabels.right
0117 right: parent.right
0118 bottom: xAxisLabels.top
0119 }
0120
0121 xRange {
0122 from: 0
0123 to: 10
0124 automatic: true
0125 }
0126
0127 yRange {
0128 from: 0
0129 to: 10
0130 automatic: true
0131 }
0132
0133 valueSources: [
0134 Charts.ModelSource { roleName: "value1"; model: barModel },
0135 Charts.ModelSource { roleName: "value2"; model: barModel },
0136 Charts.ModelSource { roleName: "value3"; model: barModel }
0137 ]
0138
0139 barWidth: 10
0140 spacing: 2
0141
0142 colorSource: Charts.ArraySource { array: ["red", "green", "blue"] }
0143 nameSource: Charts.ArraySource { array: ["Example 1", "Example 2", "Example 3"] }
0144
0145 backgroundColor: Qt.rgba(0.0, 0.0, 0.0, 0.1)
0146
0147 }
0148 }
0149
0150 RangeEditor { label: "X Axis"; range: barChart.xRange }
0151 RangeEditor { label: "Y Axis"; range: barChart.yRange }
0152
0153 RowLayout {
0154 Button { text: "Add Item"; onClicked: barModel.append({label: "New", value1: 0, value2: 0, value3: 0}) }
0155 Button { text: "Remove Item"; onClicked: barModel.remove(barModel.count - 1)}
0156 Label { text: "Bar Width" }
0157 SpinBox { from: -1; to: 1000; value: barChart.barWidth; onValueModified: barChart.barWidth = value; }
0158 Label { text: "Bar Spacing" }
0159 SpinBox { from: 0; to: 100; value: barChart.spacing; onValueModified: barChart.spacing = value; }
0160 CheckBox { text: "Stacked"; checked: barChart.stacked; onToggled: barChart.stacked = checked }
0161 Label { text: "Radius" }
0162 SpinBox { from: 0; to: 1000; value: barChart.radius; onValueModified: barChart.radius = value; }
0163
0164 ComboBox {
0165 model: [
0166 { text: "Vertical", value: Charts.BarChart.VerticalOrientation },
0167 { text: "Horizontal", value: Charts.BarChart.HorizontalOrientation }
0168 ]
0169
0170 textRole: "text"
0171 valueRole: "value"
0172
0173 onActivated: barChart.orientation = currentValue
0174 }
0175 }
0176
0177 Frame {
0178 Layout.fillWidth: true
0179 Layout.fillHeight: true
0180
0181 leftPadding: 1
0182 rightPadding: 1
0183 topPadding: 1
0184 bottomPadding: 1
0185
0186 Kirigami.Theme.inherit: false
0187 Kirigami.Theme.colorSet: Kirigami.Theme.View
0188
0189 ScrollView {
0190 anchors.fill: parent
0191 ListView {
0192 model: barModel;
0193 delegate: ItemDelegate {
0194 width: ListView.view.width
0195 height: Kirigami.Units.gridUnit * 2 + Kirigami.Units.smallSpacing
0196 contentItem: RowLayout {
0197 Label { text: "Label" }
0198 TextField {
0199 Layout.preferredWidth: 75
0200 text: model.label;
0201 onEditingFinished: barModel.setProperty(index, "label", text)
0202 }
0203 Label { text: "Value 1" }
0204 SpinBox {
0205 Layout.preferredWidth: 75
0206 from: -10000; to: 10000;
0207 stepSize: 1;
0208 value: model.value1;
0209 onValueModified: barModel.setProperty(index, "value1", value)
0210 }
0211 Label { text: "Value 2" }
0212 SpinBox {
0213 Layout.preferredWidth: 75
0214 from: -10000; to: 10000;
0215 stepSize: 1;
0216 value: model.value2;
0217 onValueModified: barModel.setProperty(index, "value2", value)
0218 }
0219 Label { text: "Value 3" }
0220 SpinBox {
0221 Layout.preferredWidth: 75
0222 from: -10000; to: 10000;
0223 stepSize: 1;
0224 value: model.value3;
0225 onValueModified: barModel.setProperty(index, "value3", value)
0226 }
0227 }
0228 }
0229 }
0230 }
0231 }
0232 }
0233 }
0234