QML - 动态柱状图
来源:互联网 发布:centos7 bugzilla端口 编辑:程序博客网 时间:2024/05/29 09:18
QML - 动态柱状图
此博客始创于:http://blog.csdn.net/lys211
转载请注明出处
效果图:
文件结构:
首先,这个并不是真的频谱柱状图,只是用随机数来实现的数组数据
Timer{
interval: 500;
repeat: true;
running: true;
onTriggered: {
if(barObject.length > 0){//生成随机数
for(var i = 0; i < barCount; i++){
barObject[i].barHeight = Math.random()*root.height;
}
}
else
{
root.createBarArea();
}
}
}
BarGraphArea.qml文件内容:
import QtQuick 2.0
Rectangle {
id:root
width: 200
height: 100
color: "white";
property var barObject: [];
property var component: Qt.createComponent("BarItem.qml");
property real spacing: 2;
property real barWidth: 15;
property real barInteral: spacing+barWidth;
property real barCount: (root.width - spacing)/(barWidth + spacing);
function resetBarArea(){
if(barObject.length <= 0)
return;
for(var i in barObject){
barObject[i].destoryBarItem();
}
barObject.length = 0;
}
function createBarArea(){
console.log("barCount:", barCount);
barCount = Math.round(barCount);
for(var i = 0; i < barCount; i++){
var object = component.createObject(root,
{
"x":root.spacing + i*barInteral,
"width":root.barWidth,
"height":root.height,
"anchors.bottom":root.bottom,
"barHeight":0,
});
barObject.push(object);
}
}
Timer{
interval: 500;
repeat: true;
running: true;
onTriggered: {
if(barObject.length > 0){//生成随机数
for(var i = 0; i < barCount; i++){
barObject[i].barHeight = Math.random()*root.height;
}
}
else
{
root.createBarArea();
}
}
}
}
BarItem.qml 文件内容:
import QtQuick 2.4
Rectangle {
id:root
width: 40
height: 100
color: "transparent";
property alias barHeight: barFg.height;
function destoryBarItem(){
root.destroy();
}
Rectangle{
id:barFg;
anchors.left: parent.left;
anchors.right: parent.right;
anchors.bottom: parent.bottom;
height: 50;
color:"transparent";
clip: true;
Rectangle{
id:barBgColor
anchors.left: parent.left;
anchors.right: parent.right;
anchors.bottom: parent.bottom;
height: root.height;
gradient: Gradient {
GradientStop {
position: 0.00;
color: "#db0707";
}
GradientStop {
position: 1.00;
color: "#06be3a";
}
}
}
}
}
代码存放地址:
0 0
- QML - 动态柱状图
- 动态生成柱状图
- PHP动态柱状图
- 动态创建qml
- qml 动态创建TableView
- Qml动态语言切换
- QML之动态加载
- JavaScript+vml动态生成柱状图
- PHP动态柱状图改进版
- echart 柱状图 实现动态加载
- Extjs5.1 柱状图动态加载
- 用amcharts动态生成柱状图
- QCustomPlot实现柱状图 动态显示
- AChartEngine图标库之动态柱状图
- Highcharts柱状图动态数据展示
- SSM echarts 柱状图 动态加载
- QML如何创建动态组件
- QML之动态菜单配置
- 编写一个函数实现n^k,使用递归实现
- 福建省2014ACM省赛H Big castle (树形dp)
- 一个64位操作系统的实现
- scanf的各种用法小结
- 机器学习Python实现 SVD 分解
- QML - 动态柱状图
- 素数筛选
- nginx 变量 获取 ngx_http_script_run 详解
- 三种思路实现自定义404页面:Tomcat、SpringMVC精准匹配、重写DispatchServlet
- dom4j
- Android app结构
- MongoDB Sharding集群部署
- C#配置文件加密
- UML建模——使用EA工具开发时序图实践及经验