Qt官方示例-QML Axes

64 篇文章 29 订阅
19 篇文章 3 订阅

QML轴线图示例,折线图,散点图。

插图

  • 使用相同轴坐标的折线图散点图

插图

代码:

ChartView {
    title: "Two Series, Common Axes"
    anchors.fill: parent
    legend.visible: false
    antialiasing: true

    ValueAxis {
        id: axisX
        min: 0
        max: 10
        tickCount: 5
    }

    ValueAxis {
        id: axisY
        min: -0.5
        max: 1.5
    }

    LineSeries {
        id: series1
        axisX: axisX
        axisY: axisY
    }

    ScatterSeries {
        id: series2
        axisX: axisX
        axisY: axisY
    }
}

/* 添加动态数据 */
Component.onCompleted: {
    for (var i = 0; i <= 10; i++) {
        series1.append(i, Math.random());
        series2.append(i, Math.random());
    }
}
  • 使用DateTimeAxis构造的图表用于显示具有日期的历史数据。

插图

代码:

ChartView {
    title: "Accurate Historical Data"
    anchors.fill: parent
    legend.visible: false
    antialiasing: true

    LineSeries {
        axisX: DateTimeAxis {
            format: "yyyy MMM"
            tickCount: 5
        }
        axisY: ValueAxis {
            min: 0
            max: 150
        }

        /* 请注意,JavaScript中的月份是以0为基础的,所以2表示3月份. */
        XYPoint { x: toMsecsSinceEpoch(new Date(1950, 2, 15)); y: 5 }
        XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 }
        XYPoint { x: toMsecsSinceEpoch(new Date(1987, 12, 31)); y: 102 }
        XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 }
        XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 2)); y: 110 }
    }
}

/* DateTimeAxis基于QDateTimes,
 * 因此我们必须将JavaScript日期转换为毫秒,
 * 使它们与DateTimeAxis值匹配。
 */ 
function toMsecsSinceEpoch(date) {
    var msecs = date.getTime();
    return msecs;
}
  • 使用CategoryAxis构造的图表,使数据更易于理解。

插图

代码:

ChartView {
    title: "Numerical Data for Dummies"
    anchors.fill: parent
    legend.visible: false
    antialiasing: true

    LineSeries {
        axisY: CategoryAxis {
            min: 0
            max: 30
            CategoryRange {
                label: "critical"
                endValue: 2
            }
            CategoryRange {
                label: "low"
                endValue: 4
            }
            CategoryRange {
                label: "normal"
                endValue: 7
            }
            CategoryRange {
                label: "high"
                endValue: 15
            }
            CategoryRange {
                label: "extremely high"
                endValue: 30
            }
        }

        XYPoint { x: 0; y: 4.3 }
        XYPoint { x: 1; y: 4.1 }
        XYPoint { x: 2; y: 4.7 }
        XYPoint { x: 3; y: 3.9 }
        XYPoint { x: 4; y: 5.2 }
    }
}
关于更多
  • 相关链接
https://doc.qt.io/qt-5/qtcharts-qmlaxes-example.html
  • Qt君公众号后台回复"Qt示例"获取更多内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值