原創|使用教程|編輯:何家巧|2022-12-21 17:14:00.507|閱讀 226 次
概述:本文主要介紹在圖標控件TeeChart for .NET中如何實現軸控制,一起來看看吧~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart for .NET是優秀的工業4.0 WinForm圖表控件,官方獨家授權漢化,集功能全面、性能穩定、價格實惠等優勢于一體。TeeChart for .NET 中文版還可讓您在使用和學習上沒有任何語言障礙,至少可以節省30%的開發時間。
在TeeChar系列教程中,上一章我們主要講解了如何實現軸控制(上),今天我們繼續為大家講解“如何實現軸控制(中)”。
注意
當改變軸標簽頻率時,請記住,TeeChart將根據AxisLabels.Separation屬性的設置來避免標簽重疊。這意味著,如果標簽頻率太高,標簽無法適應,那么TeeChart將分配 "最適合"。改變標簽角度和標簽分離是2個選項,可以幫助你適合你需要的標簽。參見標簽部分和AxisLabels.Angle屬性。
標題
標題是在軸頁的標題部分設置的。你可以改變軸的標題文本及其字體和陰影屬性。標題文本的角度和大小也可以被指定。關于運行時間,請看 AxisTitle 類。
標簽
請參閱AxisLabels類,了解標簽屬性的簡歷。
注意
當改變軸標簽頻率時,請記住,TeeChart將根據AxisLabels.Separation屬性的設置來避免標簽重疊。這意味著,如果標簽頻率太高,標簽無法適應,那么TeeChart將分配 "最適合"。改變標簽角度和標簽分離是2個選項,可能有助于你適合你所需要的標簽。參見AxisLabels.Angle屬性。
標簽格式
你可以將所有標準的數字和日期格式應用于軸的標簽。軸頁,標簽部分包含 "數值格式 "字段。如果你的數據是日期時間,字段名就會變成 "日期時間格式"。在運行時使用。
[C#.Net] tChart1.Axes.Bottom.Labels.ValueFormat = "#,##0.00;(#,##0.00)"; [VB.Net] With TChart1.Axes.Bottom .Labels.ValueFormat = "#,##0.00;(#,##0.00)" End With或者對于日期時間數據
[C#.Net] tChart1.Axes.Bottom.Labels.DateTimeFormat = "dddd/MMMM/yyyy"; [VB.Net] With TChart1.Axes.Bottom .Labels.DateTimeFormat = "dddd/MMMM/yyyy" End With MultiLine labels
軸標簽可以顯示為多行文本,而不是單行文本。行與行之間用LineSeparator字符()分開。
舉例
[C#.Net] bar1.Add(1234, "New" + Steema.TeeChart.Texts.LineSeparator + "Cars", Color.Red); bar1.Add(2000, "Old" + Steema.TeeChart.Texts.LineSeparator + "Bicycles", Color.Red); tChart1.Panel.MarginBottom = 10; [VB.Net] Bar1.Add(1234, "New" + Steema.TeeChart.Texts.LineSeparator + "Cars", Color.Red) Bar1.Add(2000, "Old" + Steema.TeeChart.Texts.LineSeparator + "Bicycles", Color.Red) TChart1.Panel.MarginBottom = 10
日期時間標簽的例子
下面將用兩行文字顯示底軸標簽,一行顯示月和日,第二行顯示年。
2月28日 3月1日 ...
2003 2003 ..
[C#.Net] bar1.Add(DateTime.Parse("28/2/2003"), 100, Color.Red); bar1.Add(DateTime.Parse("1/3/2003"), 200, Color.Red); bar1.Add(DateTime.Parse("2/3/2003"), 150, Color.Red); bar1.XValues.DateTime = true; tChart1.Axes.Bottom.Labels.DateTimeFormat = "MM/dd hh:mm"; tChart1.Axes.Bottom.Labels.MultiLine = true; tChart1.Panel.MarginBottom = 10; [VB.Net] Bar1.Add(DateValue("28/2/2003"), 100, Color.Red) Bar1.Add(DateValue("1/3/2003"), 200, Color.Red) Bar1.Add(DateValue("2/3/2003"), 150, Color.Red) Bar1.XValues.DateTime = True TChart1.Axes.Bottom.Labels.DateTimeFormat = "MM/dd hh:mm" TChart1.Axes.Bottom.Labels.MultiLine = True TChart1.Panel.MarginBottom = 10
將AxisLabels.MultiLine屬性設置為True將自動在有空格的地方分割標簽,有效地將標簽分成兩行。
第一行為'mm/dd
第二行為'hh:mm'。
在運行時,你總是可以使用OnGetAxisLabel事件,以編程方式將標簽分成幾行。
[C#.Net] private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.TChart.GetAxisLabelEventArgs e) string myLabelText = e.LabelText; tChart1.Axes.Bottom.Labels.SplitInLines(ref myLabelText, " "); e.LabelText = myLabelText; [VB.Net] Private Sub TChart1_GetAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.TChart.GetAxisLabelEventArgs) Handles TChart1.GetAxisLabel Dim myLabelText As String myLabelText = e.LabelText TChart1.Axes.Bottom.Labels.SplitInLines(myLabelText, " ") e.LabelText = myLabelText End Sub在上面的例子中,全局 "TeeSplitInLines "程序將 "LabelText "中的所有空格轉換為行的分隔符(回車)。
進一步的標簽控制可以通過使用軸事件來獲得。這些事件允許你激活/停用/改變任何一個軸的標簽。下面的例子修改了每個Label,在點的索引值前面加上一個文本短語。
[C#.Net] private void button1_Click(object sender, System.EventArgs e) bar1.FillSampleValues(20); tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Mark; private void tChart1_GetAxisLabel(object sender, Steema.TeeChart.TChart.GetAxisLabelEventArgs e) if(((Steema.TeeChart.Axis)sender).Equals(tChart1.Axes.Bottom)) e.LabelText = "Period " + Convert.ToString(e.ValueIndex); [VB.Net] Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Bar1.FillSampleValues(20) TChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Mark End Sub Private Sub TChart1_GetAxisLabel(ByVal sender As Object, ByVal e As Steema.TeeChart.TChart.GetAxisLabelEventArgs) Handles TChart1.GetAxisLabel If CType(sender, Steema.TeeChart.Axis) Is TChart1.Axes.Bottom Then e.LabelText = "Period " & e.ValueIndex End If End Sub
關于用Axis事件定制標簽的更多信息,請參見題為 "軸事件 "的章節。
如果您想了解TeeChart for .NET價格,歡迎咨詢
TeeChart for .NET 是優秀的工業4.0 WinForm圖表控件,官方獨家授權漢化,集功能全面、性能穩定、價格實惠等優勢于一體。
TeeChart for .NET技術交流QQ群:740060302 歡迎加入
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn