翻譯|使用教程|編輯:況魚杰|2020-11-10 13:22:54.647|閱讀 416 次
概述:本教程將會持續(xù)介紹有關(guān)于圖表控件Teechart的問答文章,幫助用戶解決常見問題。本篇文章將會介紹如何在兩個光標間畫線。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
TeeChart Pro ActiveX圖表組件庫提供數(shù)百種2D和3D圖形樣式,54種運算和統(tǒng)計函數(shù)以及無限數(shù)量的坐標軸和14工具箱供你選擇。該圖表控件還可以有效地用于創(chuàng)建多任務(wù)的儀表板。
Q:圖表上有兩個系列,每個系列都有一個光標。有沒有辦法在光標之間繪制一條垂直線以指示序列值之間的差異?(希望可以通過那條線顯示差值)想下面圖顯示的一樣:
還有其他辦法做到這一點嗎?
A: 首先應(yīng)該計算插值點并手動畫線,然后使用AnnotationTool繪制差異值。這里有個簡單的例子:
Dim XPos, YVal1, YVal2 As Double Private Sub Form_Load() With TChart1 .Aspect.View3D = False .Legend.Visible = False .Panel.Gradient.Visible = False .Panel.Color = vbWhite .Walls.Back.Gradient.Visible = False .Walls.Back.Color = vbWhite .Axis.Left.GridPen.Visible = False .Axis.Bottom.GridPen.Visible = False .AddSeries scFastLine .Series(0).FillSampleValues 25 .AddSeries scFastLine .Series(1).FillSampleValues 25 .Tools.Add tcAnnotate End With XPos = -1 End Sub Function InterpolateSeries(ByVal SeriesIndex As Long, ByVal XValue As Double) As Double InterpolateSeries = InterpolateLineSeries(SeriesIndex, TChart1.Series(SeriesIndex).FirstValueIndex, TChart1.Series(SeriesIndex).LastValueIndex, XValue) End Function Function InterpolateLineSeries(ByVal SeriesIndex As Long, FirstIndex As Integer, LastIndex As Integer, XValue As Double) As Double Dim index As Integer Dim dx, dy, val As Double index = FirstIndex Do While ((TChart1.Series(SeriesIndex).XValues.Value(index) <= XValue) And (index < LastIndex)) index = index + 1 Loop ' safeguard If (index < 1) Then index = 1 ElseIf (index >= TChart1.Series(SeriesIndex).Count) Then index = TChart1.Series(SeriesIndex).Count - 1 End If ' y=(y2-y1)/(x2-x1)*(x-x1)+y1 dx = TChart1.Series(SeriesIndex).XValues.Value(index) - TChart1.Series(SeriesIndex).XValues.Value(index - 1) dy = TChart1.Series(SeriesIndex).YValues.Value(index) - TChart1.Series(SeriesIndex).YValues.Value(index - 1) If (dx <> 0) Then InterpolateLineSeries = dy * (XValue - TChart1.Series(SeriesIndex).XValues.Value(index - 1)) / dx + TChart1.Series(SeriesIndex).YValues.Value(index - 1) Else InterpolateLineSeries = 0 End If End Function Private Sub TChart1_OnAfterDraw() With TChart1.Axis If XPos > -1 Then TChart1.Canvas.Pen.Style = psSolid TChart1.Canvas.Pen.Color = vbBlack TChart1.Canvas.DrawLine XPos, .Left.CalcYPosValue(YVal1), XPos, .Left.CalcYPosValue(YVal2) End If End With End Sub Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) XPos = X XVal = TChart1.Axis.Bottom.CalcPosPoint(XPos) YVal1 = InterpolateSeries(0, XVal) YVal2 = InterpolateSeries(1, XVal) TChart1.Tools.Items(0).asAnnotation.Text = Format$(YVal1 - YVal2, "#,##0.##") TChart1.Tools.Items(0).asAnnotation.Left = XPos + 5 TChart1.Tools.Items(0).asAnnotation.Top = TChart1.Axis.Left.CalcYPosValue(YVal1) + (TChart1.Axis.Left.CalcYPosValue(YVal2) - TChart1.Axis.Left.CalcYPosValue(YVal1)) / 2 TChart1.Repaint End Sub
希望以上問答能夠給您提供幫助,如果您有任何的疑惑或者建議都可以在評論區(qū)留言,我們會盡快回復(fù)。
相關(guān)資料推薦:
TeeChart Pro ActiveX更新內(nèi)容板塊>>
TeeChart Pro ActiveX已加入在線訂購,現(xiàn)在搶購可立享特別優(yōu)惠!!!
關(guān)注慧聚IT微信公眾號???,了解產(chǎn)品的最新動態(tài)及最新資訊。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: