翻译|使用教程|编辑:董玉霞|2022-08-17 10:01:13.247|阅读 93 次
概述:本文主要介绍TeeChart for .NET使用教程中关于系列值列表的相关介绍。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
本文主要介绍TeeChart for .NET使用教程中关于系列值列表的相关介绍。
TeeChart 系列将它们的值存储在可通过 ValueList 类访问和修改的 Valuelist 中。
您可以访问列表中的任何值:
例子
[C#] MessageBox.Show(bar1.YValues[3].ToString()); //Displays value of 4th point (index starts at 0) of a BarSeries [VB.Net] MsgBox(Bar1.YValues(3)) 'Displays value of 4th point (index starts at 0) of a BarSeries
以这种方式访问的值可用于在系列数据上设置陷阱:
[C#] for(int i = 0; i < bar1.Count; ++i) { if(bar1.YValues[i] > 500) { MessageBox.Show("Value: (" + bar1.XValues[i] + ", " + bar1.YValues[i] + ") exceeds limit"); } } [VB.Net] Dim i As Integer For i = 0 To Bar1.Count If Bar1.YValues(i) > 500 Then MsgBox("Value: (" & Bar1.XValues(i) & ", " & Bar1.YValues(i) & ") exceeds limit") End If Next
可以通过一些 Series 方法和几个 Chart 事件使用的点 ValueIndex 获得相同的值。
例子
[C#] private void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.Windows.Forms.MouseEventArgs e) { if(s.Equals(bar1)) { MessageBox.Show("ValueIndex is: " + valueIndex.ToString()); MessageBox.Show("Point's YValue is " + bar1.YValues[valueIndex].ToString()); } } [VB.Net] Private Sub TChart1_ClickSeries(ByVal sender As Object, ByVal s As Steema.TeeChart.Styles.Series, ByVal valueIndex As Integer, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickSeries If s Is Bar1 Then MsgBox("ValueIndex is: " & valueIndex) MsgBox("Point's YValue is " & Bar1.YValues(valueIndex)) End If End Sub
此代码根据用户的鼠标点击修改 BarSeries Bar 的值。
例子
使用 TChart.ClickSeries 事件来确定用户单击的位置。
[C#] private void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.Windows.Forms.MouseEventArgs e) { UpDatePoint(valueIndex,tChart1.Axes.Left.CalcPosPoint((e.Y))); } [VB.Net] Private Sub TChart1_ClickSeries(ByVal sender As Object, ByVal s As Steema.TeeChart.Styles.Series, ByVal valueIndex As Integer, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickSeries UpDatePoint(valueIndex, TChart1.Axes.Left.CalcPosPoint(e.Y)) End Sub
调用 UpdatePoint Sub 例程来修改 Bar 的值:
[C#] private void UpDatePoint(int Bar, double Y) { if(Bar < tChart1.Series[0].Count) { tChart1.Series[0].YValues[Bar] = Y; tChart1.Series[0].Repaint(); } } [VB.Net] Private Sub UpDatePoint(ByVal Bar As Integer, ByVal Y As Double) If Bar < TChart1.Series(0).Count Then TChart1.Series(0).YValues(Bar) = Y TChart1.Series(0).Repaint() End If End Sub
上一节介绍了 Series 事件的一些用法。本节展示了一些额外的用途。
您可以使用 OnClickSeries 事件来获取有关系列的几乎所有信息。 这些示例适用于具有日期时间数据的系列,例如这些测试值可用于以下事件示例:
[C#] private void button1_Click(object sender, System.EventArgs e) { Random rnd = new Random(); line1.XValues.DateTime = true; line1.Pointer.Visible = true; line1.Add(DateTime.Parse("25/12/2002 10:30:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("25/12/2002 22:30:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("26/12/2002 09:20:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("26/12/2002 23:30:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("27/12/2002 11:10:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("27/12/2002 20:15:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("28/12/2002 08:15:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("28/12/2002 21:45:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("29/12/2002 12:45:00"),rnd.Next(100),"", Color.Red); line1.Add(DateTime.Parse("29/12/2002 22:05:00"),rnd.Next(100),"", Color.Red); line1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top; } private void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.Windows.Forms.MouseEventArgs e) { //The below will show the Value of the nearest Point, not the exact Axis value at the clicked X and Y. MessageBox.Show("Date is: " + DateTime.FromOADate(line1.XValues[valueIndex]) + " Value is: " + line1.YValues[valueIndex]); } [VB.Net] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim rnd As New Random() Line1.XValues.DateTime = True Line1.Pointer.Visible = True Line1.Add(DateTime.Parse("25/12/2002 10:30:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("25/12/2002 22:30:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("26/12/2002 09:20:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("26/12/2002 23:30:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("27/12/2002 11:10:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("27/12/2002 20:15:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("28/12/2002 08:15:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("28/12/2002 21:45:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("29/12/2002 12:45:00"), rnd.Next(100), "", Color.Red) Line1.Add(DateTime.Parse("29/12/2002 22:05:00"), rnd.Next(100), "", Color.Red) Line1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top End Sub Private Sub TChart1_ClickSeries(ByVal sender As Object, ByVal s As Steema.TeeChart.Styles.Series, ByVal valueIndex As Integer, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.ClickSeries 'The below will show the Value of the nearest Point, not the exact Axis value at the clicked X and Y. MsgBox("Date is: " & DateTime.FromOADate(Line1.XValues(valueIndex)) _ & " Value is: " & Line1.YValues(valueIndex)) End Sub
对于那些使用 TChart 指针的系列,您可以使用 OnGetSeriesPointer 事件访问和修改指针: 如果 Point 高于最后一个,则绘制 Uptriangle,如果更低,则绘制 DownTriangle 等。
[C#] private void line1_GetPointerStyle(Steema.TeeChart.Styles.CustomPoint series, Steema.TeeChart.Styles.GetPointerStyleEventArgs e) { if(e.ValueIndex > 0) { if(line1.YValues[e.ValueIndex] > line1.YValues[e.ValueIndex - 1]) { e.Style = Steema.TeeChart.Styles.PointerStyles.Triangle; } else if(line1.YValues[e.ValueIndex] < line1.YValues[e.ValueIndex - 1]) { e.Style = Steema.TeeChart.Styles.PointerStyles.DownTriangle; } else { e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond; } } else { e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond; } } [VB.Net] Private Sub Line1_GetPointerStyle(ByVal series As Steema.TeeChart.Styles.CustomPoint, ByVal e As Steema.TeeChart.Styles.GetPointerStyleEventArgs) Handles Line1.GetPointerStyle If e.ValueIndex > 0 Then If (Line1.YValues(e.ValueIndex) > Line1.YValues(e.ValueIndex - 1)) Then e.Style = Steema.TeeChart.PointerStyles.Triangle ElseIf (Line1.YValues(e.ValueIndex) < Line1.YValues(e.ValueIndex - 1)) Then e.Style = Steema.TeeChart.Styles.PointerStyles.DownTriangle Else e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond End If Else e.Style = Steema.TeeChart.Styles.PointerStyles.Diamond End If End Sub
使用 OnGetSeriesMark 事件在运行时修改标记内容。以下代码根据相对于最后一个的值改变 MarkText;
TeeChart 支持通过 DragMarks Tool 在重叠的情况下拖动标记:
[C#] private void line1_GetSeriesMark(Steema.TeeChart.Styles.Series series, Steema.TeeChart.Styles.GetSeriesMarkEventArgs e) { if(e.ValueIndex > 0) { if(line1.YValues[e.ValueIndex] > line1.YValues[e.ValueIndex - 1]) { e.MarkText = e.MarkText + " (Up)"; } else if(line1.YValues[e.ValueIndex] < line1.YValues[e.ValueIndex - 1]) { e.MarkText = e.MarkText + " (Down)"; } else { e.MarkText = e.MarkText + " (No Change)"; } } } [VB.Net] Private Sub Line1_GetSeriesMark(ByVal series As Steema.TeeChart.Styles.Series, ByVal e As Steema.TeeChart.Styles.GetSeriesMarkEventArgs) Handles Line1.GetSeriesMark If (e.ValueIndex > 0) Then If (Line1.YValues(e.ValueIndex) > Line1.YValues(e.ValueIndex - 1)) Then e.MarkText = e.MarkText + " (Up)" ElseIf (Line1.YValues(e.ValueIndex) < Line1.YValues(e.ValueIndex - 1)) Then e.MarkText = e.MarkText + " (Down)" End If Else e.MarkText = e.MarkText + " (No Change)" End If End Sub
最后 2 个事件产生的图表外观是:
本次关于.NET图表控件TeeChart for .NET教程关于使用系列就介绍到这里了,下一篇将介绍使用函数的相关内容。
如果您想了解TeeChart for .NET价格,欢迎咨询
TeeChart for .NET 是优秀的工业4.0 WinForm图表控件,官方独家授权汉化,集功能全面、性能稳定、价格实惠等优势于一体。
欢迎加入TeeChart for .NET技术交流QQ群:740060302
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn