翻譯|使用教程|編輯:凌霄漢|2022-03-21 11:03:34.620|閱讀 297 次
概述:本次TeeChart Pro .NET使用教程將為大家帶來如何處理高級軸和圖例操作。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart Pro 將自動為您定義所有 Axis 標簽,并提供足夠的靈活性來定制您可能有的任何特定要求。 TeeChart Pro 提供真正的多軸。 這些在設計或運行時可用,并為 Axis 定義提供了無數的可能性和靈活性。
將系列數據添加到圖表時會自動設置軸刻度。 您可以在設計時或運行時使用 Axis 屬性更改默認值。
添加新系列時,TeeChart 編輯器的軸頁面的比例部分將顯示選擇自動,其他選項顯示為灰色。 顯示的所有值都是數字。
當系列在系列 -> 常規頁面上將日期時間設置為 true(對于該軸)時,TeeChart 編輯器的軸頁面的比例部分將顯示選擇自動,其他選項灰顯。 值與日期時間值一起顯示。
自動選擇最佳軸刻度范圍以適合您的數據。 如果您關閉“自動”,比例部分將變為灰色選項,您可以更改軸值。 重要的是,請記住從頁面左側的軸列表中選擇要配置的軸。
在設計時使用 TeeChart 編輯器將線系列添加到圖表,然后使用以下代碼添加命令按鈕:
[C#.Net] Random rnd = new Random(); for(int i = 0; i <= 40; ++i) line1.Add(Convert.ToDouble(i),rnd.Next(100),Color.Red); [VB.Net] Dim i As Integer For i = 0 To 40 Line1.Add(Convert.ToDouble(i), Rnd() * 100, Color.Red) Next i
運行按鈕中的代碼將繪制一個具有 40 個隨機值的 Line Series。 在設計時轉到 TeeChart 編輯器。 在 Axis 頁面的 Bottom Axis scales 部分中關閉 Automatic 'off'。 您現在可以配置軸刻度的最大值和最小值。 再次運行代碼將根據您為軸配置的值顯示值。 使用鼠標右鍵,您可以滾動查看剩余值。
您可以使用以下代碼在運行時更改最大值和最小值:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Automatic = false; bottomAxis.Maximum = 36; bottomAxis.Minimum = 5; [VB.Net] With TChart1.Axes.Bottom .Automatic = False .Maximum = 36 .Minimum = 5 End With
您可以將軸刻度最大值和最小值分別設置為自動。 例如:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.AutomaticMaximum = true; bottomAxis.AutomaticMinimum = false; bottomAxis.Minimum = 5; [VB.Net] With TChart1.Axes.Bottom .AutomaticMaximum = True .AutomaticMinimum = False .Minimum = 5 End With
您可以定制軸的間隔。 從 Axis 頁面的 Scales 部分選擇 Desired Increment 組合框并添加您需要的增量。 您可以在運行時通過代碼更改它:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Increment = 20; [VB.Net] With TChart1.Axes.Bottom .Increment = 20 End With
如果您的數據是日期時間(您可以通過轉到系列,常規頁面將數據設置為您的系列的日期時間),圖表->軸頁面,比例部分將顯示日期時間范圍。 從 Desired Increment 組合框中顯示的范圍中選擇增量并添加一些示例數據:
[C#.Net] Random rnd = new Random(); DateTime today = DateTime.Today; TimeSpan oneDay = TimeSpan.FromDays(1); line1.XValues.DateTime = true; for(int i = 1; i <= 25; ++i) line1.Add(today,rnd.Next(100),Color.Red); today += oneDay; [VB.Net] Dim i As Integer Dim Today As DateTime = DateTime.Today Dim OneDay As TimeSpan = TimeSpan.FromDays(1) Line1.XValues.DateTime = True For i = 1 To 25 Line1.Add(Today, Rnd() * 100, Color.Red) Today = Today.Add(OneDay) Next
在運行時更改增量:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays); [VB.Net] With TChart1.Axes.Bottom .Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays) End With
更改軸標簽頻率時,請記住 TeeChart 將根據 AxisLabels.Separation 屬性的設置避免標簽重疊。 這意味著如果標簽頻率太高而無法適應標簽,則 TeeChart 將分配“最佳匹配”。 更改標簽角度和標簽分隔是 2 個選項,可以幫助您適應所需的標簽。
標題在 Axis 頁面的 Titles 部分中設置。 您可以更改軸的標題文本及其字體和陰影屬性。 也可以指定標題文本的角度和大小。
您可以將所有標準數字和日期格式應用于軸標簽。 軸頁面,標簽部分包含“值格式”字段。 如果您的數據是日期時間,則字段名稱將更改為“日期時間格式”。 在運行時使用:
[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
DateTime 標簽的示例: 下面將在兩行文本中顯示底部軸標簽,一行顯示月份和日期,第二行顯示年份:
2 月 28 日 Mar-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”中的所有空格轉換為行分隔符(返回)。
軸 AxisLabels.Angle 屬性也可以與多線軸標簽一起使用。
進一步的標簽控制可以通過使用 Axis 事件來獲得。 這些事件允許您激活/停用/更改任何單個軸標簽。 以下示例修改每個標簽,在點索引值前面放置一個文本短語:
[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
正態對數標記可以通過以下方式設置:
[C#.Net] private void button1_Click(object sender, System.EventArgs e) Random rnd = new Random(); Steema.TeeChart.Axis leftAxis = tChart1.Axes.Left; tChart1.Aspect.View3D = false; bar1.Marks.Visible = false; for(int i = 0; i <= 100; ++i) bar1.Add(rnd.Next(100) * i); leftAxis.LogarithmicBase = 10; leftAxis.Logarithmic = true; leftAxis.SetMinMax(0, 10000); leftAxis.Labels.ValueFormat = "#e+0"; //exponential format [VB.Net] Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer TChart1.Aspect.View3D = False Bar1.Marks.Visible = False For i = 0 To 10000 Step 100 Bar1.Add(Rnd() * i) Next With TChart1.Axes.Left .LogarithmicBase = 10 .Logarithmic = True .SetMinMax(0, 10000) .Labels.ValueFormat = "#e+0" ' exponential format End With End Sub
標簽將根據對數基數(默認為 10)設置,因此在這種情況下,標簽為 1、10、100、1000、10000。
有 3 種刻度類型和 2 種網格類型。 您可以更改每個刻度和網格類型的長度、寬度和顏色。 可以通過“Ticks”選項卡對 Ticks、它們關聯的 Grid 和 Inner Ticks 進行更改; 可以通過“次要”選項卡對次要刻度及其相關網格進行更改。 TeeChart Pro 版本 5 的新增功能是能夠更改寬度大于 1(默認)的刻度和網格的樣式。
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.Ticks.Length = 7; bottomAxis.Ticks.Color = Color.Green; bottomAxis.MinorTickCount = 10; [VB.Net] With TChart1.Axes.Bottom .Ticks.Length = 7 .Ticks.Color = Color.Green .MinorTickCount = 10 End With
軸具有修改每個軸的位置的屬性。 在此示例中,軸移動了圖表總寬度的 50%,因此它顯示在圖表中心:
[C#.Net] Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; bottomAxis.PositionUnits = PositionUnits.Percent; bottomAxis. RelativePosition = 50 [VB.Net] With TChart1.Axes.Bottom .PositionUnits = PositionUnits.Percent .RelativePosition = 50 End With
如果您想了解TeeChart for .NET正版價格,歡迎咨詢
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn