在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屬性中獲取;
注: 若哪位知道其他實現的方法,望能不吝相告!
