翻译|使用教程|编辑:李爽夏|2018-11-16 15:35:33.000|阅读 1003 次
概述:本教程介绍了在TeeChart Pro ActiveX中如何使用系列。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
大多数系列类型(ODBC数据源教程8和函数教程7除外)使用Add和ADDXY方法添加数据。 有一些例外,请参阅下表,了解它们如何区别的示例:
Series Type | Add Series points | Delete Series points |
Basic |
||
Gantt |
GanttSeries.AddGantt GanttSeries.AddGanttColor |
Series.Delete |
Shape |
ShapeSeries.X0, ShapeSeries.Y0, ShapeSeries.X1, ShapeSeries.Y1 |
TChart.RemoveSeries |
Bubble |
BubbleSeries.AddBubble |
Series.Delete |
Line |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Bar |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
HorizBar |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Area |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Point |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Pie |
Series.Add Series.AddNull Series.AddArray |
Series.Delete |
Fast Line |
FastLineSeries.AddRealTime Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
HorizLine |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
HorizArea |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
3D |
||
Surface |
SurfaceSeries.AddXYZ SurfaceSeries.AddArrayXYZ SurfaceSeries.AddArrayGrid |
Series.Delete |
Contour |
ContourSeries.AddXYZ ContourSeries.AddArrayXYZ ContourSeries.AddArrayGrid |
Series.Delete |
Waterfall |
Waterfall.AddXYZ Waterfall.AddArrayXYZ Waterfall.AddArrayGrid |
Series.Delete |
Color Grid |
ColorGrid.AddXYZ ColorGrid.AddArrayXYZ ColorGrid.AddArrayGrid |
Series.Delete |
Vector 3D |
Vector3D.AddVector Vector3D.AddXYZ Vector3D.AddArrayXYZ Vector3D.AddArrayGrid |
Series.Delete |
Tower |
Tower.AddXYZ Tower.AddArrayXYZ Tower.AddArrayGrid |
Series.Delete |
Point3D |
Point3DSeries.AddXYZ |
Series.Delete |
Triangle Surf. |
TriSurface.AddXYZ TriSurface.AddArrayXYZ TriSurface.AddArrayGrid |
Series.Delete |
Other |
||
Bar 3D |
Bar3D.AddBar Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Image Bar |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Wind Rose |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Clock |
None |
None |
Line Point |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Bar Join |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Calender |
Calendar.Date |
None |
Big Candle |
|
|
ImagePoint |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
DeltaPoint |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Extended |
||
Polar |
PolarSeries.AddPolar |
Series.Delete |
Radar |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Arrow |
ArrowSeries.AddArrow |
Series.Delete |
Bezier |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Donut |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Smith |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Pyramid |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Map |
Map.Shapes.Add |
Series.Delete |
Gauge |
Gauge.Value |
None |
Financial |
||
Candle |
CandleSeries.AddCandle |
Series.Delete |
Volume |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
Point & Figure |
PointFigure.AddOHLC |
Series.Delete |
Stats |
||
Error |
ErrorSeries.AddErrorBar |
Series.Delete |
Error Bar |
ErrorBarSeries.AddErrorBar |
Series.Delete |
High-Low |
HighLow.AddHighLow |
Series.Delete |
Histogram |
Series.Add Series.AddXY Series.AddNull Series.AddNullXY Series.AddArray |
Series.Delete |
BoxPlot |
BoxPlot.Median BoxPlot.Quartile1 BoxPlot.Quartile3 BoxPlot.InnerFence1 BoxPlot.InnerFence3 BoxPlot.OuterFence1 BoxPlot.OuterFence3 |
TChart.RemoveSeries |
Horizontal BoxPlot |
BoxPlot.Median BoxPlot.Quartile1 BoxPlot.Quartile3 BoxPlot.InnerFence1 BoxPlot.InnerFence3 BoxPlot.OuterFence1 BoxPlot.OuterFence3 |
TChart.RemoveSeries |
Funnel |
Funnel.AddSegment |
Series.Delete |
请注意,不使用Add或AddXY方法的Series,可以在系列中访问其特定于系列的数据添加方法。“as [SeriesType]”属性(例如,Series.asCandle.AddCandle中的AddCandle; Series.asGantt.AddGantt中的AddGantt))。
添加点时,可以手动为点添加颜色
例如:
TChart1.Series(0).Add 46, "My first value", vbYellow
或者使用TeeChart常量clTeeColor,告诉TeeChart分配颜色。 TeeChart将为每个新系列选择最多16种独特且尚未使用的颜色中的一种。
例如:
TChart1.Series(0).Add 46, "My first value", clTeeColor
可以为Point添加“非颜色”,以便为ValueList中的值保留空间,而不会在Chart上显示。
例如:
TChart1.Series(0).Add 46, "My hidden value", clNone
使用Series.Delete从Series中删除一个点。
例如:
TChart.Series(0).Delete(7) ; (8th point - Points index start at zero)
可以从系列中删除点范围:
Private Sub Command1_Click()
TChart1.Series(0).DeleteRange 5, 5 '(Deletes points 5, 6, 7, 8, & 9 from the Series)
End Sub
Private Sub Form_Load()
With TChart1
.AddSeries scLine
.Series(0).FillSampleValues 20
End With
End Sub
例如:
TChart1.Series(0).AddNull "my null value"
例如:
TChart1.AddSeries(scLine) ' Adds a Line Series
(*注意:Microsoft在Internet Explorer中实现的VBScript不支持TeeChart Enum常量(scLine,scBar等)。您必须使用等价整数(0,1等)来添加新的Series类型。请参阅ESeriesClass 完整列表。此规则适用于使用VBscript的所有TeeChart ENum常量。
例如:
TChart1.AddSeries(0) ' Adds a Line Series (vbscript)
With TChart1.Series(0) .HorizontalAxis = aTopAxis .VerticalAxis = aRightAxis End With
每个轴可以关联1个以上的系列。 TeeChart将决定适合与Axis匹配的系列的最佳比例,但您可以自己更改Axis音阶(参见Axis Tutorial)。可以添加附加轴,它们将复制与前4轴相对应的刻度(参见教程部分附加轴)。
With TChart1.Series(1) .DataSource = "Series1" ' Series1 es Series(0) .SetFunction tfCopy End With
更改系列订单
使用图表编辑器可以非常轻松地更改系列顺序。 转到编辑器的彩票走势图,突出显示要移动的系列。 使用右侧的箭头按钮以系列顺序向上或向下移动系列。 系列订单将决定图表中系列相对于其他系列的相对显示位置。 将系列设置为“Active=False”将从图表中隐藏系列,但保持其数据内容不变。
要通过代码更改系列顺序,请使用TChart.ExchangeSeries。
TChart1.ExchangeSeries 0, 1 ' Change Series(0) with Series(1) in the index order
*注意。 交换Series后,系列的索引将被更改。 因此,如果代码重新运行,上面的代码行将永久地交换2系列'0'和'1',因为0变为1,1变为0。
msgbox TChart1.Series(0).XValues.Value(3) 'Displays value of 4th point (index starts at 0) in Series0
以这种方式访问的值可用于设置Series数据的陷阱:
With TChart1.Series(0) For t = 0 To .Count - 1 If .YValues.Value(t) > 900 Then MsgBox "Value: " & .XValues.Value(t) & ", " _ & .YValues.Value(t) & " exceeds limit" End If Next t End With
可以通过一些Series方法和几个Chart事件使用的PointIndex值获得相同的值。
Private Sub TChart1_OnClickSeries(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) If SeriesIndex = 0 Then MsgBox "ValueIndex is: " & ValueIndex MsgBox "Point's Y value is: " & TChart1.Series(SeriesIndex).YValues.Value(ValueIndex) End If TChart1.StopMouse 'Use Stopmouse to prevent Zoom event activating End Sub
'Use the OnClickSeries or OnclickBackground event to determine where the user has clicked. Private Sub TChart1_OnClickBackground(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) If CInt(TChart1.Axis.Bottom.CalcPosPoint(X)) > -1 Then Select Case Button Case 1 UpdatePoint CInt(TChart1.Axis.Bottom.CalcPosPoint(X)), CInt(TChart1.Axis.Left.CalcPosPoint(Y)) End Select End If End Sub Private Sub TChart1_OnClickSeries(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) UpdatePoint ValueIndex, CInt(TChart1.Axis.Left.CalcPosPoint(Y)) End Sub
在这两种情况下,请调用UpdatePoint Sub例程来修改Bar的值:
Private Sub UpdatePoint(Bar, Y As Double) If Bar < TChart1.Series(0).Count Then TChart1.Series(0).YValues.Value(Bar) = Int(Y) End If End Sub
'These examples apply to a Series with Datetime data 'eg These test values may be used for the following event examples Private Sub Command1_Click() TChart1.AddSeries scLine With TChart1.Series(0) .XValues.DateTime = True .asLine.Pointer.Visible = True .Marks.Visible = True 'Here with European dateformat .AddXY DateValue("1/1/1999") + TimeValue("11:59:00"), 45, "", clTeeColor .AddXY DateValue("1/1/1999") + TimeValue("21:59:00"), 23, "", clTeeColor .AddXY DateValue("2/1/1999") + TimeValue("11:59:00"), 43, "", clTeeColor .AddXY DateValue("2/1/1999") + TimeValue("21:59:00"), 12, "", clTeeColor .AddXY DateValue("3/1/1999") + TimeValue("10:59:00"), 12, "", clTeeColor .AddXY DateValue("3/1/1999") + TimeValue("21:59:00"), 11, "", clTeeColor .AddXY DateValue("4/1/1999") + TimeValue("11:59:00"), 34, "", clTeeColor .AddXY DateValue("4/1/1999") + TimeValue("21:59:00"), 15, "", clTeeColor .AddXY DateValue("4/1/1999") + TimeValue("23:59:00"), 28, "", clTeeColor .AddXY DateValue("5/1/1999") + TimeValue("09:59:00"), 32, "", clTeeColor .AddXY DateValue("5/1/1999") + TimeValue("21:59:00"), 32, "", clTeeColor End With TChart1.Axis.Bottom.SetMinMax TChart1.Series(0).XValues.First, _ TChart1.Series(0).XValues.Last + (2 / 12) End Sub
您可以使用此事件显示Series'Clicked'值
Private Sub TChart1_OnClickSeries(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) 'The below will show the Value of the nearest Point, not the exact Axis value at the clicked X and Y. MsgBox ("Date is:" & Format(TChart1.Series(SeriesIndex).XValues.Value(ValueIndex), "dd/mm/yyyy hh:mm:ss") _ & " Value is:" & TChart1.Series(SeriesIndex).YValues.Value(ValueIndex)) TChart1.StopMouse End Sub
或者:
Private Sub TChart1_OnClickSeries(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) 'The below will show the exact Axis values at the X,Y clicked. MsgBox ("Date is:" & Format(TChart1.Series(SeriesIndex).XScreenToValue(X), "dd/mm/yyyy hh:mm:ss") _ & " Value is:" & TChart1.Series(SeriesIndex).YScreenToValue(Y)) TChart1.StopMouse End Sub
'Drawing an Uptriangle if the Point is higher than the last, DownTriangle if lower, etc. Private Sub TChart1_OnGetSeriesPointerStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, AStyle As TeeChart.EPointerStyle) If ValueIndex > 0 Then If TChart1.Series(SeriesIndex).YValues.Value(ValueIndex) > TChart1.Series(SeriesIndex).YValues.Value(ValueIndex - 1) Then AStyle = psTriangle ElseIf TChart1.Series(SeriesIndex).YValues.Value(ValueIndex) < TChart1.Series(SeriesIndex).YValues.Value(ValueIndex - 1) Then AStyle = psDownTriangle Else AStyle = psDiamond End If Else AStyle = psDiamond End If End Sub
此代码根据相对于最后一个箭头长度的值更改Marktext也会更改。 TeeChart支持在重叠的情况下拖动标记,请参阅VB示例文件夹中的VB“移动标记”示例。
Private Sub TChart1_OnGetSeriesMark(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, MarkText As String) If ValueIndex > 0 Then If TChart1.Series(SeriesIndex).YValues.Value(ValueIndex) > TChart1.Series(SeriesIndex).YValues.Value(ValueIndex - 1) Then MarkText = MarkText & " (Up)" ElseIf TChart1.Series(SeriesIndex).YValues.Value(ValueIndex) < TChart1.Series(SeriesIndex).YValues.Value(ValueIndex - 1) Then TChart1.Series(SeriesIndex).Marks.ArrowLength = 5 MarkText = MarkText & Chr$(13) & "(Down)" Else TChart1.Series(SeriesIndex).Marks.ArrowLength = 25 MarkText = MarkText & Chr$(13) & "(No change)" End If End If End Sub
Private Sub Form_Load() With TChart1 .Aspect.View3D = False .AddSeries scBar .Series(0).FillSampleValues 10 .Series(0).Marks.Visible = False End With End Sub Private Sub TChart1_OnMouseEnterSeries(ByVal SeriesIndex As Long) Dim clicked As Long clicked = TChart1.Series(SeriesIndex).GetMousePoint ' Show Series name and point index and value Label1.Caption = "Series: " + TChart1.Series(SeriesIndex).Name + _ " point:" + Str(clicked) + _ " value:" + Str(TChart1.Series(SeriesIndex).YValues.Value(clicked)) End Sub Private Sub TChart1_OnMouseLeaveSeries(ByVal SeriesIndex As Long) Label1.Caption = "" End Sub
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn