qml: QtChart横纵轴label设置;

在qml中,使用ChartView作为图表展示区域, 但是并没有给定接口用来设置xlabel,ylabel。 

没得办法,只能采用笨方案: (我的方法如下)

import QtQuick 2.0
import MaterialUI 1.0
import  QtCharts 2.0  as  CHARTS
 CHARTS.ChartView{
    id: chart;
    property alias xlabel: xlabel.text;
    property alias ylabel: ylabel.text;
    property int rotation: -90;
    Rectangle{
        id:  xlabelArea;
        height: chart.margins.bottom;
        anchors{
            left: chart.left;
            right:chart.right;
            bottom: chart.bottom;
        }

        Text{id: xlabel; anchors.centerIn:  parent;}
    }

    Rectangle{
        id: ylabelArea;
        width: chart.margins.left;
        anchors{
            left: chart.left;
            top: chart.top;
            bottom: chart.bottom;
        }
        Text{
            id: ylabel;anchors.centerIn: parent; rotation: -90;
        }
    }
}

该方法需要了解两个知识点:

1)  文字旋转;        ------------     Item自带rotation属性,可以实现任意角度的旋转;

2)  margin大小(ChartView与图表之间的间隔);   ---------------------  QChartView与Chart之间的大小可以从margins属性中获取;

 

注:  若哪位知道其他实现的方法,望能不吝相告!

 

转载于:https://www.cnblogs.com/yinwei-space/p/9021045.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值