QML 中的线系列多色图

问题描述 投票:0回答:1

我将一个列表绘制成线系列图。列表长度可能在4000左右

  1. 我想将 1000 以上范围内的 Y 轴值着色为红色,将小于 1000 的范围着色为绿色。这可能吗?
  2. 为了提高性能,我可以使用任何替代方法来代替 FOR 循环吗?由于长度为 4000,因此需要更多时间来绘制。请建议一些其他的而不是 FOR 循环
import QtQuick 2.9
import QtQuick.Window 2.2
import QtCharts 2.0
import QtQuick.Controls 2.15

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("ADC Chart")

    ChartView {
        id: chart
        anchors.fill: parent
        theme: ChartView.ChartThemeBrownSand
        antialiasing: true


        Component.onCompleted: {
            line.clear();
            for (let i = 0; i < r_manager.ADC1y.length; ++i) {          
                line.append(i, r_manager.ADC1y[i]);
            }
        }

        LineSeries {
            id: line
            name: "ADC1"
            axisX: ValueAxis {
                titleText: "Sample"
                min: 0
                max: r_manager.ADC1y.length
            }

            axisY: ValueAxis {
                titleText: "ADC"
                min: -400
                max: 400
            }
        }
    
    }

}
  1. Line系列多色。这可能吗?
  2. 为了提高性能。请建议其他一些代替 FOR 循环
qt qml lineseries
1个回答
0
投票

以下示例演示了如何使用

Colorize
组件将绿色更改为红色。

import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
Page {
    background: Rectangle { color: "#848895" }
    title: "Colorize Demo"
    
    Image {
        id: chart
        source: "https://stephenquan.github.io/images/qt/madewithqt.png"
    }
    
    Item {
        width: chart.width
        height: slider.value
        clip: true
        Colorize {
            width: chart.width
            height: chart.height
            source: chart
            hue: 0.0
            saturation: 1.0
            lightness: 0.0
        }
    }

    Slider {
       id: slider
       from: 0
       to: chart.height
       orientation: Qt.Vertical
       rotation: 180
       Component.onCompleted: value = 155
    }
}

您可以在线尝试!

© www.soinside.com 2019 - 2024. All rights reserved.