LiveCharts文檔-3開始-6軸Axes
通常來說,你可以自定義LiveChart里的任何東西,Axes也不例外。下面這幅圖展示了Axes。
Title標題
可以使用Title屬性給axis添加一個標簽
myAxis.Title = "Population"
合並軸
當你想需要一些空間的時候,可以在chart中合並一些axis,可以將Axis.IsMerged屬性設置為true。下面的圖片展示了合並Axis和沒有合並的Axis的區別。
軸定位
不管你有1個還是10個軸,你總是可以制定軸的堆疊位置;使用 Axis.Position屬性, 可以通過 RightTop, LeftBottom等可選選項進行調整。
new Axis { Position = Position = AxisPosition.LeftBottom }
強制分隔
每個軸分隔都是根據chart的尺寸,值的范圍,自動計算的,但是有些時候你需要靜態的風格符,比如每30s,每10個單位,另外一個比較有用的應用就是顯示所有的標簽,這種情況下,設定分隔步長為1,將會強迫chart繪制所有的labels。如果要移除所有步長,可以設置回null,這樣它又可以自動計算了。
當然要注意,強制步長可能會產生嚴重的性能問題,如果沒有正確使用,比如你的range是0到1000,如果你設置步長為1,那么它將繪制1000個分隔出來。
//設置步長為1
new Axis
{
Separator = new Separator
{
Step = 1,
IsEnabled = false
}
}
//下面這個例子使用30s作為步長,可以去時間相關的章節查看更多。
new Axis
{
Separator = new Separator
{
Step = TimeSpan.FromSeconds(30).Ticks,
IsEnabled = false
}
}
分隔的樣式
notice setting Axis.Separator.IsEnabled property to false will make the separator invisible.
注意,如果設置Axis.Separator.IsEnabled 為false的話,分隔就會不可見。
cartesianChart1.AxisX.Add(new Axis
{
IsMerged = true,
Separator = new Separator
{
StrokeThickness = 1,
StrokeDashArray = new System.Windows.Media.DoubleCollection(new double[] { 2 }),
Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(64, 79, 86))
}
});
cartesianChart1.AxisY.Add(new Axis
{
IsMerged = true,
Separator = new Separator
{
StrokeThickness = 1.5,
StrokeDashArray = new System.Windows.Media.DoubleCollection(new double[] { 4 }),
Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(64, 79, 86))
}
});
本節完