My requirement is I want to display a Image box when a user perform a mouse over on a bar in the chart. Currently in mouse over we are displaying the text such as label, Percentage etc can we display Image as well.
Thanks Akshay
You can use a hidden Rectangle tool to show the desired image and use the provided events to change its visibility, position, or the image loaded.
Ie, using OnMouseEnterSeries
/OnMouseLeaveSeries
, but the same could be done with OnMouseMove
event:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcMarksTip
TChart1.Tools.Add tcRectangle
TChart1.Tools.Items(1).Active = False
TChart1.Tools.Items(1).asRectangle.AllowDrag = False
TChart1.Tools.Items(1).asRectangle.AllowResize = False
TChart1.Tools.Items(1).asRectangle.Shape.Transparency = 0
End Sub
Private Sub TChart1_OnMouseEnterSeries(ByVal SeriesIndex As Long)
ValueIndex = TChart1.Series(SeriesIndex).Clicked(TChart1.MousePosition.X, TChart1.MousePosition.Y)
If ValueIndex = 2 Then
TChart1.Tools.Items(1).Active = True
TChart1.Tools.Items(1).asRectangle.Shape.Picture.LoadImage "C:\tmp\ImageForValueIndex2.png"
TChart1.Tools.Items(1).asRectangle.Left = TChart1.MousePosition.X
TChart1.Tools.Items(1).asRectangle.Top = TChart1.MousePosition.Y
End If
End Sub
Private Sub TChart1_OnMouseLeaveSeries(ByVal SeriesIndex As Long)
TChart1.Tools.Items(1).Active = False
End Sub
Edit:
As noticed in the comment below, TeeChart VCL v2014.11 introduced SystemHints
property as explained here:
MarksTip tool new property SystemHints (boolean default True in VCL, False in Firemonkey). When False, a normal TeeShape object is used to paint the tiptool instead of using the VCL system mechanism.
ChartTool3.SystemHints := False; ChartTool3.Format.Font.Size:=14;
The only disadvantadge compared to system hints is the shape cannot be displayed outside the chart bounds.
When SystemHints is False, the new Format property (of type TTeeShape) contains all the formatting properties (Brush, Pen, Font, etc) to display the hint.
Since TeeChart ActiveX is a wrapper from TeeChart VCL, you can use this new feature from TeeChart ActiveX v2014.0.0.1.
So you just have to keep in mind to set SystemHints
to False if you want to use the TeeShape properties. Here it is a simple example:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcMarksTip
TChart1.Tools.Items(0).asMarksTip.Format.Picture.LoadImage "C:\tmp\ImageForAllValues.jpg"
TChart1.Tools.Items(0).asMarksTip.SystemHints = False
End Sub