系列活动
TeeChart for .NET制图控件提供了一套出色的通用组件套件,可满足无数的制图要求,也针对重要的垂直领域,例如金融,科学和统计领域。制图控件提供了一套出色的通用组件套件,可满足无数的制图要求,也针对重要的垂直领域,例如金融,科学和统计领域。
前一节介绍了系列事件的一些用法。本节将展示一些其他用途。
加入官方社群740060302,欢迎相互交流
OnClickSeries
你可以使用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
点击复制
OnGetSeriesPointerStyle
对于那些使用TChart指针的系列,你可以使用OnGetSeriesPointer事件访问和修改指针:
如果该点高于上一个三角形,则绘制上一个三角形;如果该点低于上一个三角形,则绘制下一个三角形,以此类推。
[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
使用OnGetSeriesMark事件在运行时修改标记内容。以下代码根据相对于最后一个的值改变MarkText;
TeeChart支持通过DragMarks工具拖动重叠的标记:
[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
点击复制
最后两个事件所产生的图表外观如下:
如需下载产品TeeChart for NET ,请点击产品名进入下载页面