Chart

EventDescription16131007
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.YYYY
BeforeDoubleClickOccurs before an embedded chart or chart object on a chart sheet is double clicked. This should be used instead of the OnDoubleClick property.YYYY
BeforeRightClickOccurs before an embedded chart or chart object on a chart sheet is right clicked.YYYY
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
YYYY
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.YYYY
MouseDownOccurs when a mouse button is pressed while the pointer is over an embedded chart or chart sheet.YYYY
MouseMoveOccurs when the mouse pointer is moved over the chartYYYY
MouseUpOccurs when a mouse button is released while the pointer is over an embedded chart or chart sheetYYYY
ResizeOccurs when a chart is resizedYYYY
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.
YYYY
SeriesChangeOccurs when a value of a chart data point changes.YYYY

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

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