【TeeChart .NET教程】(六)使用系列

上一篇:【TeeChart .NET教程】(五)图例设计

下一篇:【TeeChart .NET教程】(七)使用函数

【下载TeeChart.Net最新版本】

(一)Series——系列类型

TChart Series类是所有Series类型的父属性,使用TeeChart在线帮助获取任何Series Type的帮助时,请点击继承类型列表中Series类的链接,然后单击Series成员,其中将包含所有继承属性和方法的列表。

1.1 系列类结构

作为TeeChart类型库结构的一小部分背景,下面是对系列类和接口的解释。下图显示了TeeChart系列类之间的关系。所有类都派生自通用的“Series”类,因此共享“Series”属性和方法。几个抽象类派生自Series(Custom3DSeries,CustomBarSeries和CircledSeries),这些类以灰色突出显示,并且它们的接口不能直接用于编程,它们的特性由其后代Series类型继承。所有派生系列(橙色)均可在TeeChart图库中访问,以包含在用户的图表中。以这种方式派生的TeeChart系列允许通过公共索引结构对继承的属性和方法进行可编程访问(请参阅本节后面的示例代码)。

 

在设计时使用TChart编辑器更容易添加Series,也可以在运行时创建新的和不同的系列类型并将其添加到同一TChart。

[C#.Net]

//Add a series at runtime 
private void button1_Click(object sender, System.EventArgs e) 
        { 
            Steema.TeeChart.Styles.Area tmpAreaSeries = new Steema.TeeChart.Styles.Area(tChart1.Chart);  
            tmpAreaSeries.FillSampleValues(4); 
            //Or 
            //Steema.TeeChart.Styles.Area tmpAreaSeries = new Steema.TeeChart.Styles.Area(); 
            //tChart1.Series.Add(tmpAreaSeries); 
            //tmpAreaSeries.FillSampleValues(4); 
        } 

[VB.Net]

'Add a series at runtime 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
         Dim tmpAreaSeries As New Steema.TeeChart.Styles.Area(TChart1.Chart) 
        tmpAreaSeries.FillSampleValues(4) 
        'Or 
        'Dim tmpAreaSeries As New Steema.TeeChart.Styles.Area() 
        'TChart1.Series.Add(tmpAreaSeries) 
        'tmpAreaSeries.FillSampleValues(4) 
End Sub 

对于在设计时创建的任何系列,新系列都可以使用所有AreaSeries属性和方法。

在同一图表中混合不同系列类的一个示例是在设计时使用TeeChart编辑器将区域(Series(0)), Bar (Series(1)) and Line (Series(2))系列添加到图表中。所有访问一个公共索引结构,图表的系列列表。使用该系列可能如下所示:

[C#.Net]

private void Form1_Load(object sender, System.EventArgs e) 
        { 
            //You could add the Series at runtime  
            Steema.TeeChart.Styles.Area area1 = new Steema.TeeChart.Styles.Area(tChart1.Chart); 
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart); 
            Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart); 
 
            //Use Series common properties  
            tChart1.Series[0].FillSampleValues(10); 
            tChart1.Series[1].FillSampleValues(10); 
            tChart1.Series[2].FillSampleValues(10); 
            tChart1.Series[1].Marks.Visible = false; 
            tChart1.Series[2].Marks.Visible = false; 
 
            //Modify Bar specific properties  
            bar1.BarStyle = Steema.TeeChart.Styles.BarStyles.Pyramid; //Change Bar type  
            bar1.Pen.Color = Color.Yellow; //Bar bounding lines colour  
 
            //Modify Line specific properties  
            line1.Stairs = true; //Set line to Stairs  
            line1.LinePen.Color = Color.Blue; //LineSeries bounding lines colour  
 
            //Modify Area specific properties  
            area1.AreaBrush.Style = System.Drawing.Drawing2D.HatchStyle.Cross; //Area fill pattern  
        }  

[VB.Net]

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        'You could add the Series at runtime  
        Dim Area1 As New Steema.TeeChart.Styles.Area(TChart1.Chart) 
        Dim Bar1 As New Steema.TeeChart.Styles.Bar(TChart1.Chart) 
        Dim Line1 As New Steema.TeeChart.Styles.Line(TChart1.Chart) 
 
        'Use Series common properties  
        TChart1.Series(0).FillSampleValues(10) 
        TChart1.Series(1).FillSampleValues(10) 
        TChart1.Series(2).FillSampleValues(10) 
        TChart1.Series(1).Marks.Visible = False 
        TChart1.Series(2).Marks.Visible = False 
 
        'Modify Bar specific properties  
        Bar1.BarStyle = Steema.TeeChart.Styles.BarStyles.Pyramid 'Change Bar type  
        Bar1.Pen.Color = Color.Yellow 'Bar bounding lines colour  
 
        'Modify Line specific properties  
        Line1.Stairs = True 'Set line to Stairs  
        Line1.LinePen.Color = Color.Blue 'LineSeries bounding lines colour  
 
        'Modify Area specific properties  
        Area1.AreaBrush.Style = System.Drawing.Drawing2D.HatchStyle.Cross 'Area fill pattern  
End Sub 

1.2 选择

系列类型为图表选择系列类型很大程度上取决于用户自己对图表的要求。但是,有时候,由于要绘制的变量数量,Chart的选择可能取决于哪种Series类型支持输入变量的数量。下表显示了每种Series类型允许的变量数。

 

标签可用于扩展2变量Series Type的值。请参阅下面的示例,该示例在同一图表中使用3个Bar Series类型的实例。

示例

使用条形系列类型

产品代码月产量数量

10 Jan 300

10 Feb 325

10 Mar 287

12 Jan 175

12 Feb 223

12 Mar 241

14 Jan 461

14 Feb 470

14 Mar 455

以最简单的形式,数据生成以下图表,按月对信息进行分组:

 

代码:

[C#.Net]

foreach(Steema.TeeChart.Styles.Series tSeries in tChart1.Series) 
{tSeries.Marks.Visible = false;} 
tChart1.Header.Text = "Production results"; 
 
bar1.Add(300,"Jan"); 
bar1.Add(325,"Feb"); 
bar1.Add(287,"Mar"); 
bar1.Title = "Product10"; 
 
bar2.Add(175,"Jan"); 
bar2.Add(223,"Feb"); 
bar2.Add(241,"Mar"); 
bar2.Title = "Product12"; 
 
bar3.Add(461,"Jan"); 
bar3.Add(470,"Feb"); 
bar3.Add(455,"Mar"); 
bar3.Title = "Product14"; 

[VB.Net]

Dim TSeries As Steema.TeeChart.Styles.Series 
For Each TSeries In TChart1.Series 
    TSeries.Marks.Visible = False 
Next 
TChart1.Header.Text = "Production results" 
 
Bar1.Add(300, "Jan") 
Bar1.Add(325, "Feb") 
Bar1.Add(287, "Mar") 
Bar1.Title = "Product10" 
 
Bar2.Add(175, "Jan") 
Bar2.Add(223, "Feb") 
Bar2.Add(241, "Mar") 
Bar2.Title = "Product12" 
 
Bar3.Add(461, "Jan") 
Bar3.Add(470, "Feb") 
Bar3.Add(455, "Mar") 
Bar3.Title = "Product14" 

或(grouping by product):

 

代码:

[C#.Net]

foreach(Steema.TeeChart.Styles.Series tSeries in tChart1.Series) 
{tSeries.Marks.Visible = false;} 
tChart1.Header.Text = "Production results"; 
 
bar1.Add(300,"Product10"); 
bar1.Add(175,"Product12"); 
bar1.Add(461,"Product14"); 
bar1.Title = "Jan"; 
 
bar2.Add(325,"Product10"); 
bar2.Add(223,"Product12"); 
bar2.Add(470,"Product14"); 
bar2.Title = "Feb"; 
 
bar3.Add(287,"Product10"); 
bar3.Add(241,"Product12"); 
bar3.Add(455,"Product14"); 
bar3.Title = "Mar"; 

[VB.Net]

Dim TSeries As Steema.TeeChart.Styles.Series 
For Each TSeries In TChart1.Series 
    TSeries.Marks.Visible = False 
Next 
TChart1.Header.Text = "Production results" 
 
Bar1.Add(300, "Product10") 
Bar1.Add(175, "Product12") 
Bar1.Add(461, "Product14") 
Bar1.Title = "Jan" 
 
Bar2.Add(325, "Product10") 
Bar2.Add(223, "Product12") 
Bar2.Add(470, "Product14") 
Bar2.Title = "Feb" 
 
Bar3.Add(287, "Product10") 
Bar3.Add(241, "Product12") 
Bar3.Add(455, "Product14") 
Bar3.Title = "Mar"     

上表(Stock)中添加了新值。

产品代码月份数量产生库存水平

10 Jan 300 600

10 Feb 325 715

10 Mar 287 676

12 Jan 175 245

12 Feb 223 270

12 Mar 241 315

14 Jan 461 800

14 Feb 470 755

14 Mar 455 835

表中的库存值通常高于月产量,因此显示它们会给出下面的图表(这次是2D)。图表使用线系列来区分股票。

 

代码:

将以下内容添加到前面第一个示例的代码中:

[C#.Net]

line1.Add(600,"Jan"); 
line1.Add(715,"Feb"); 
line1.Add(676,"Mar"); 
line1.Title = "Product10 Stock";  
line1.Color = bar1.Color; 
 
line2.Add(245,"Jan"); 
line2.Add(270,"Feb"); 
line2.Add(315,"Mar"); 
line2.Title = "Product10 Stock";   
line2.Color = bar2.Color; 
 
line3.Add(800,"Jan"); 
line3.Add(755,"Feb"); 
line3.Add(835,"Mar"); 
line3.Title = "Product10 Stock";   
line3.Color = bar3.Color; 

[VB.Net]

Line1.Add(600, "Jan") 
Line1.Add(715, "Feb") 
Line1.Add(676, "Mar") 
Line1.Title = "Product10 Stock" 
Line1.Color = Bar1.Color 
 
Line2.Add(245, "Jan") 
Line2.Add(270, "Feb") 
Line2.Add(315, "Mar") 
Line2.Title = "Product10 Stock" 
Line2.Color = Bar2.Color 
 
Line3.Add(800, "Jan") 
Line3.Add(755, "Feb") 
Line3.Add(835, "Mar") 
Line3.Title = "Product10 Stock" 
Line3.Color = Bar3.Color 

1.3 将数据添加到系列

大多数系列类型(ADO.NET数据源教程8和函数教程7除外)使用Add方法的24个泛型重载来添加数据。有一些例外,请参见下表:

 

除了ShapeSeries之外,所有系列特定的Add方法都会自动添加为通用Add方法的进一步重载,因此可以从那里访问(例如candleSeries1.Add(new)日期时间(2002,11,27),100400200300))。添加点示例时,可以为点添加颜色

颜色

[C#.Net]

bar1.Add(50,"Tomatoes",Color.Tomato); 

[VB.Net]

Bar1.Add(50, "Tomatoes", Color.Tomato) 

或者,用户可以允许TeeChart分配颜色。如果Series.ColorEach = True,TeeChart将为每个新系列选择最多19种唯一且尚未使用的颜色之一,或者为每个新系列点选择一种颜色。

例:

[C#.Net]


Random rnd = new Random(); 
bar1.ColorEach = true; 
for(int i = 0; i < 19; ++i) 
{ 
     int higher = i + 65; 
     char letter = (char) higher; 
     bar1.Add(rnd.Next(100),letter.ToString()); 
} 

[VB.Net]


Dim i As Integer 
Bar1.ColorEach = True 
For i = 0 To 19 
    Bar1.Add(Rnd() * 100, Chr(i + 65)) 
Next

可以向Point添加透明颜色,以便为ValueList中的值保留空间,而不会在Chart上显示。

例:

[C#.Net]


bar1.Add(45, "My Transparent Bar", Color.Transparent); 

[VB.Net]


Bar1.Add(45, "My Transparent Bar", Color.Transparent) 

1.4 从系列中删除数据点

使用系列中删除数据点。删除系列中的点。Series.Delete有两个重载:


public Void Delete(System.Int32)

删除系列中的第n个点。


public Void Delete(System.Int32,System.Int32)

从系列的第n个点开始删除多个点。

例:

[C#.Net]


bar1.Delete(7,2);  (deletes two points starting from the 8th Series point (index starts at zero)) 

[VB.Net]


Bar1.Delete(7, 2)  (deletes two points starting from the 8th Series point (index starts at zero))

Series.Clear清除系列中的所有点。

1.5 将Null点添加到Series

Series.Add有三个重载,允许用户向系列添加Null点:添加一个新的null(透明)点。


public Int32 Add()

使用指定的文本添加新的null点。


public Int32 Add(System.String)

在指定的x值处添加一个带有指定文本的新null值


public Int32 Add(System.Double,System.String)

上面的第二个重载将为系列添加一个Null点,允许你为该点定义一个标签,但在该点为系列留下一个中断。在Line Series的情况下,中断前的最后一个点不会连接到中断后的第一个点。

[C#.Net]


line1.Add(“Null Point”); 

[VB.Net]


Line1.Add("Null Point")
(二)在图表上混合系列类型

TeeChart Pro提供了一个空的Chart Canvas作为数据系列的背景,这意味着没有预定义图表类型,用户可以将所需的图表类型定义为要显示的系列类型的混合。由于某些系列类型的特殊性质,在Chart上将Series类型与另一个类型混合是不切实际的。当用户到达添加新系列时,TeeChart会通过在图表库中显示不合适的系列类型来帮助用户。用户可以在一个图表中放置的系列数量没有实际限制。

2.1 添加新系列

使用TeeChart编辑器(参见教程1)或按代码添加系列。

例:

[C#.Net]


private void button1_Click(object sender, System.EventArgs e) 
        { 
            Bar bar1 = new Bar(tChart1.Chart); 
            bar1.FillSampleValues(10); 
        } 

[VB.Net]


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        Dim Bar1 As New Steema.TeeChart.Styles.Bar(TChart1.Chart) 
        Bar1.FillSampleValues(10) 
End Sub 

系列被添加到SeriesList,可以通过Index,TChart1.Series(Index)访问,从第一个系列的0开始。TeeChart Pro为系列添加默认名称(系列0,系列1等)。用户可以使用Series.Title属性修改名称。

2.2 选择

添加到图表系列的轴系列会自动将左轴和下轴作为参考轴,用户可以通过选择相关系列的“Series General(系列常规)”页面来更改图表编辑器中的参考轴。有4个轴可供选择,Top,Left,Bottom和Right。通过代码,更改轴将如下所示:

[C#.Net]


bar1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right; 
bar1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top;

[VB.Net]


Bar1.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right 
Bar1.HorizAxis = Steema.TeeChart.Styles.HorizontalAxis.Top 

每个轴可以关联1个以上的系列。TeeChart将决定适合与Axis匹配的系列的最佳比例,但用户可以自己更改Axis音阶(参见Axis Tutorial(轴控制))。可以添加额外的轴; 他们将从前4个轴复制与其对应关联的比例。

2.3 连接系列

用户可以使用Series作为另一个Series的数据源,通过设置第二系列的数据源,可以使用图表编辑器完成此操作。转到“Series(系列)”选项卡“Datasource(数据源)”页面,选择“Function”作为数据源类型,将出现两个列表框,可用系列和选定系列,选择要用作当前系列的数据源的系列,然后在上面的Combobox中,标题为Functions:,选择Average作为功能类型,然后单击Apply按钮。请注意,以这种方式,任何Series都可以定义为任何其他Series的函数,Function Type可以是Function组合框中可用的任何列表。要通过代码执行相同操作,请参阅下文:

[C#.Net]


Steema.TeeChart.Functions.Average average1 = new Steema.TeeChart.Functions.Average(); 
line1.Function = average1; 
line1.DataSource = bar1; 
bar1.FillSampleValues(10); 
line1.CheckDataSource(); 

[VB.Net]


Dim Average1 As New Steema.TeeChart.Functions.Average()
Line1.Function = Average1 
Line1.DataSource = 
Bar1 Bar1.FillSampleValues(10)
Line1.CheckDataSource()

2.4 更改系列订单

使用图表编辑器更改系列订单非常简单,转到编辑器的首页,突出显示要移动的系列。使用右侧的箭头按钮以系列顺序向上或向下移动系列。系列订单将决定图表中系列相对于其他系列的相对显示位置。将系列设置为“Active=False”将从图表中隐藏系列,但保持其数据内容不变。要通过代码更改系列顺序,请使用Series.Exchange。

[C#.Net]


tChart1.Series.Exchange(0, 1);  //Change Series(0) with Series(1) in the index order 

[VB.Net]


TChart1.Series.Exchange(0, 1) 'Change Series(0) with Series(1) in the index order 

*注意。交换Series后,系列的索引将被更改。因此,如果代码重新运行,上面的代码行将永久地交换2系列'0'和'1',因为0变为1,1变为0。

(三)系列价值表

TeeChart系列将其值存储在可通过ValueList类访问和修改的Valuelist中。

3.1 访问系列值

用户可以访问列表中的任何值:

示例:

[C#.Net]


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 

以这种方式访问​​的值可用于设置Series数据:

[C#.Net]


            { 
                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事件使用的PointIndex值获得相同的值。

[C#.Net]


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 

3.2 使用值的示例

此代码根据用户的鼠标单击修改BarSeries Bar的值。

示例

使用TChart.ClickSeries事件确定用户单击的位置。

[C#.Net]


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#.Net]


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事件的一些用法,本节介绍了一些其他用途。

4.1 OnClickSeries

用户可以使用OnClickSeries事件来获取有关Series的几乎所有信息。

这些示例适用于具有日期时间数据的系列,例如,这些测试值可用于以下事件示例:

[C#.Net]


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  

4.2 OnGetSeriesPointerStyle

对于那些使用 TChart指针的系列,用户可以使用OnGetSeriesPointer事件访问和修改指针:

如果Point高于最后一个,则绘制一个Uptriangle,如果更低,则绘制一个UpTriangle等。

[C#.Net]


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 

4.3 OnGetSeriesMark

使用OnGetSeriesMark事件在运行时修改标记内容,以下代码根据相对于最后一个的值改变MarkText;

TeeChart支持通过DragMarks工具在重叠的情况下拖动标记:

[C#.Net]


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个事件产生的图表效果是:

 

转载于:https://my.oschina.net/u/3905944/blog/1920017

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值