Chart

EventDescription3652116131007
Activate
Cast (ChartEvents_Event)
Occurs when an embedded chart or chart object on a chart sheet is selected. This should be used instead of the OnSheetActivate property.YYYYYY
BeforeDoubleClickOccurs before an embedded chart or chart object on a chart sheet is double clicked. This should be used instead of the OnDoubleClick property.YYYYYY
BeforeRightClickOccurs before an embedded chart or chart object on a chart sheet is right clicked.YYYYYY
CalculateOccurs before any new data is plotted or data changes.
This is raised on a chart sheet that was updated because data it referenced changed. This event does not occur until the chart is forced to redraw. So if the chart is not currently visible because it is not selected or displayed in its own window the event will not be raised until the chart is visible
YYYYYY
DeactivateOccurs when a new embedded chart or chart sheet is activate and another embedded chart, chart sheet or worksheet is selected. This should be used instead of the OnSheetDeactivate property.YYYYYY
MouseDownOccurs when a mouse button is pressed while the pointer is over an embedded chart or chart sheet.YYYYYY
MouseMoveOccurs when the mouse pointer is moved over the chartYYYYYY
MouseUpOccurs when a mouse button is released while the pointer is over an embedded chart or chart sheetYYYYYY
ResizeOccurs when a chart is resizedYYYYYY
Select
Cast (ChartEvents_Event)
Occurs when a chart element is selected
Raised when the selected element within a chart sheet changes. The combination of the three parameters allows you to determine exactly what element is selected.
YYYYYY
SeriesChangeOccurs when a value of a chart data point changes.YYYYYY

Writing Chart Events

This object does not have events enabled by default.
You must write your own event handler routines when you want to capture chart events for embedded charts.


If you want to capture the chart events for a specific chart sheet the event handlers are available in an identical way to the worksheet level events.


The advantage of this method is that you can run the same event handler for different chart objects.


Public WithEvents ExcelChartEvents As Chart 

Dim Chart1 As New EventClass
Dim Chart2 As New EventClass

Set Chart1.ExcelChartEvents = Worksheets(1).ChartObjects(1).Chart
Set Chart2.ExcelChartEvents = Worksheets(1).ChartObjects(2).Chart

Embedded Chart Events

Add a class module to trap the events
Add a standard module to hook the event handler to your charts
The exact code will depend on your situation but there are a wide range of different scenarios from all charts in all sheets in all workbooks to just a single chart in a specific workbook.


Chart Select Event

Or you can use a Chart object declared in a class module to write an event handler for both embedded charts and chart sheets.
This event has three arguments passed to it
ElementID - Identifies the chart element (xlChartItem) enumeration
Arg1 - provides additional information

xlErrorBarsSeriesIndex
xlXErrorBarsSeriesIndex
xlYErrorBarsSeriesIndex
xlLegendEntrySeriesIndex
xlLegendKeySeriesIndex
xlUpBarsGroupIndex
xlDownBarsGroupIndex
xlSeriesLinesGroupIndex
xlHiLoLinesGroupIndex
xlDropLinesGroupIndex
xlRadarAxisLabelsGroupIndex
xlShapeShapeIndex
xlPivotChartDropZoneDropZoneType

Arg2 - provides additional information

xlSeriesSeriesIndexPointIndex
xlDataLabelSeriesIndexPointIndex
xlTrendLineSeriesIndexTrendLineIndex
xlAxisAxisIndexAxisType
xlMajorGridlinesAxisIndexAxisType
xlMinorGridlinesAxisIndexAxisType
xlAxisTitleAxisIndexAxisType
xlDisplayUnitLabelAxisIndexAxisType
xlPivotChartFieldButtonDropZoneTypePivotFieldIndex

Chart MouseUp Event

This event has four arguments passed to it
Button - Identifies which button was released (xlMouseButton)
Shift - Identifies if any other keys were pressed (Ctrl, Shift, Alt)
x - Identifies the x-coordinate
y - Identifies the y-coordinate


Change Events

Change events are typically raised when a user exist cell edit mode by leaving the cell or pressing Enter
Change events can also be raised when a cell is linked to external data and it changes as a result of refreshing the external data.
Change events are not raised as a result of recalculation
Application.SheetChange
Workbook.SheetChange
Worksheet.Change


Event Procedures

Private Sub Chart_Activate() 
End Sub

Private Sub Chart_BeforeDoubleClick( _
   ByVal ElementID As Long, _
   ByVal Arg1 As Long, _
   ByVal Arg2 As Long, _
   ByRef Cancel As Boolean)
End Sub

Private Sub Chart_BeforeRightClick( _
   ByRef Cancel As Boolean)
End Sub

Private Sub Chart_Calculate()
End Sub

Private Sub Chart_Deactivate()
End Sub

Private Sub Chart_MouseDown( _
   ByVal Button As Long, _
   ByVal Shift As Long, _
   ByVal x As Long, _
   ByVal y As Long)
End Sub

Private Sub Chart_MouseMove( _
   ByVal Button As Long, _
   ByVal Shift As Long, _
   ByVal x As Long, _
   ByVal y As Long)
End Sub

Private Sub Chart_MouseUp( _
   ByVal Button As Long, _
   ByVal Shift As Long, _
   ByVal x As Long, _
   ByVal y As Long)
End Sub

Private Sub Chart_Resize()
End Sub

Private Sub Chart_Select( _
   ByVal ElementID As Long, _
   ByVal Arg1 As Long, _
   ByVal Arg2 As Long)
End Sub

Private Sub Chart_SeriesChange( _
   ByVal SeriesIndex As Long, _
   ByVal PointIndex As Long)
End Sub

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext