Warning, /frameworks/kquickcharts/examples/charts/LineChart.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: "Line Chart"
0020 
0021     ListModel {
0022         id: lineModel;
0023         dynamicRoles: true;
0024 
0025         Component.onCompleted: {
0026             append({label: "Item 1", value1: 10, value2: 15, value3: 20})
0027             append({label: "Item 2", value1: 15, 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.LineChartControl {
0045                 id: lineChart
0046 
0047                 anchors.fill: parent
0048 
0049                 valueSources: [
0050                     Charts.ModelSource { roleName: "value1"; model: lineModel },
0051                     Charts.ModelSource { roleName: "value2"; model: lineModel },
0052                     Charts.ModelSource { roleName: "value3"; model: lineModel }
0053                 ]
0054 
0055                 names: ["Example 1", "Example 2", "Example 3"]
0056 
0057                 pointDelegate: Item {
0058                     Rectangle {
0059                         anchors.centerIn: parent
0060                         width: lineChart.lineWidth + Kirigami.Units.smallSpacing;
0061                         height: width
0062                         radius: width / 2;
0063                         color: parent.Charts.LineChart.color
0064 
0065                         MouseArea {
0066                             id: mouse
0067                             anchors.fill: parent
0068                             hoverEnabled: true
0069                         }
0070 
0071                         ToolTip.visible: mouse.containsMouse
0072                         ToolTip.text: "%1: %2".arg(parent.Charts.LineChart.name).arg(parent.Charts.LineChart.value)
0073                     }
0074                 }
0075             }
0076         }
0077 
0078         RangeEditor { label: "X Axis"; range: lineChart.xRange }
0079         RangeEditor { label: "Y Axis"; range: lineChart.yRange }
0080 
0081         RowLayout {
0082             Button { text: "Add Item"; onClicked: lineModel.append({label: "New", value1: 0, value2: 0, value3: 0}) }
0083             Button { text: "Remove Item"; onClicked: lineModel.remove(lineModel.count - 1)}
0084             Label { text: "Line Width" }
0085             SpinBox { from: 0; to: 1000; value: lineChart.lineWidth; onValueModified: lineChart.lineWidth = value; }
0086             Label { text: "Fill Opacity" }
0087             SpinBox { from: 0; to: 100; value: lineChart.fillOpacity * 100; onValueModified: lineChart.fillOpacity = value / 100; }
0088             CheckBox { text: "Stacked"; checked: lineChart.stacked; onToggled: lineChart.stacked = checked }
0089             CheckBox { text: "Smooth"; checked: lineChart.chart.smooth; onToggled: lineChart.chart.smooth = checked }
0090         }
0091 
0092         Frame {
0093             Layout.fillWidth: true
0094             Layout.fillHeight: true
0095 
0096             leftPadding: 1
0097             rightPadding: 1
0098             topPadding: 1
0099             bottomPadding: 1
0100 
0101             Kirigami.Theme.inherit: false
0102             Kirigami.Theme.colorSet: Kirigami.Theme.View
0103 
0104             ScrollView {
0105                 anchors.fill: parent
0106                 ListView {
0107                     model: lineModel;
0108                     delegate: ItemDelegate {
0109                         width: ListView.view.width
0110                         height: Kirigami.Units.gridUnit * 2 + Kirigami.Units.smallSpacing
0111                         contentItem: RowLayout {
0112                             Label { text: "Label" }
0113                             TextField {
0114                                 Layout.preferredWidth: 75
0115                                 text: model.label;
0116                                 onEditingFinished: lineModel.setProperty(index, "label", text)
0117                             }
0118                             Label { text: "Value 1" }
0119                             SpinBox {
0120                                 Layout.preferredWidth: 75
0121                                 from: -10000; to: 10000;
0122                                 stepSize: 1;
0123                                 value: model.value1;
0124                                 onValueModified: lineModel.setProperty(index, "value1", value)
0125                             }
0126                             Label { text: "Value 2" }
0127                             SpinBox {
0128                                 Layout.preferredWidth: 75
0129                                 from: -10000; to: 10000;
0130                                 stepSize: 1;
0131                                 value: model.value2;
0132                                 onValueModified: lineModel.setProperty(index, "value2", value)
0133                             }
0134                             Label { text: "Value 3" }
0135                             SpinBox {
0136                                 Layout.preferredWidth: 75
0137                                 from: -10000; to: 10000;
0138                                 stepSize: 1;
0139                                 value: model.value3;
0140                                 onValueModified: lineModel.setProperty(index, "value3", value)
0141                             }
0142                         }
0143                     }
0144                 }
0145             }
0146         }
0147     }
0148 }