Why is event PreUpdate and PostUpdate not triggered in ChartContainer?
Show older comments
Hi all,
I’ve created a ChartContainer in MATLAB R2024b and need to track when its update routine finishes so I can restore an internal property to its original value. During setup, I added listeners for the PreUpdate and PostUpdate events of the ChartContainer.
However, when I change a property, the update method runs, but neither the PreUpdate nor PostUpdate events seem to fire.
Below I share the class implementation:
classdef TestComponent < matlab.graphics.chartcontainer.ChartContainer
%% Properties
properties (AbortSet)
% Internal use. Indicates update is required, triggered by external
% property.
TriggerUpdate (1,1) logical = false;
end %properties
properties (Transient, NonCopyable, Hidden, SetAccess = protected, UsedInUpdate = false)
% Event listener array
EventListeners (1,:) event.listener
end
%% Protected Methods
methods (Access = protected)
function setup(obj)
% Setup routine
% Show setup routine is executed
disp('setup')
% Setup listeners to all events in the class
metaClass = meta.class.fromName(class(obj));
eventList = {metaClass.EventList.Name};
listenAcces = {metaClass.EventList.ListenAccess};
% Initialize listener to post-update event
for idx = 1:numel(eventList)
if ~strcmpi(listenAcces{idx}, {'public', 'protected'})
continue
end
obj.EventListeners(end+1) = listener(obj, ...
eventList{idx}, @(s,e) obj.showEvent(e));
end
end %function
function update(obj)
% Update routine
% Show update routine is executed
disp('update')
end %function
end %methods
methods
function showEvent(obj, e)
disp(e)
end %function
end %methods
end
Does anyone know why these events aren’t triggered? For ComponentContainer, the events work as expected.
Accepted Answer
More Answers (1)
Andrew Ouellette
on 23 Dec 2025
I can't give you a great answer as to why the behavior differs between ChartContainer and ComponentContainer. However, I expect that you can achieve the behavior you desire without needing to create listeners to undocumented events.
In particular, you mention that you want to perform some clean up action after "update" has finished. Could you just place your clean up functionality at the bottom of the update function?
I imagine you could have an implementation like the following:
classdef TestComponent < matlab.graphics.chartcontainer.ChartContainer
methods (Access=protected)
function setup(this)
% You can often leave this method empty
end
function update(this)
preUpdate(this);
% Insert your current update code here
postUpdate(this);
end
function preUpdate(this)
% Setup transient data for update
end
function postUpdate(this)
% Cleanup transient data from update
end
end
end
Categories
Find more on Developing Chart Classes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!