Updating a figure in a GUI pops up a new figure, what's wrong?

5 views (last 30 days)
I am trying to make a program that displays live chart data from a broker once in a period. The period could be for example 5 seconds or 15 minutes.
I have made a GUI and a Timer but always when the program starts all the updated candles comes to new figure (only one) but not into the figure in the GUI.
Attached is some code:
This is in the openingFcn of the GUI .m-file
handles.timer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly
'Period', 5, ... % Initial period is 5 sec.
'TimerFcn', {@updateChart,hObject}); % Specify callback
guidata(hObject, handles);
start(handles.timer);
% Choose default command line output for OAPIGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
And this is the updateChart callback funtion:
function updateChart(hObject,eventdata,hfigure)
% Get new data, one candle at a time
[ openBid, openAsk, highBid, highAsk, lowBid, lowAsk, ...
closeBid, closeAsk, volume] = ...
DataExtract(GetHistory('EUR_USD', 'S5', '1'));
handles = guidata(hfigure);
% How many times the chart has already updated
k = handles.timer.TasksExecuted
% Populate the beginnings of the vectors with NaNs to draw the newest
% candle on the right spot on the chart.
highBid = [NaN(k,1) ; highBid];
lowBid = [NaN(k,1) ; lowBid];
closeBid = [NaN(k,1) ; closeBid];
openBid = [NaN(k,1) ; openBid];
axes(handles.axes1);
candle(highBid, lowBid, closeBid, openBid);
hold on;
I have read https://se.mathworks.com/matlabcentral/answers/102384-how-do-i-make-my-gui-plot-into-an-axes-within-the-gui-figure-rather-than-inside-of-a-new-figure-in-m but I'm still getting a new figure. The first candle goes to the GUI's figure which is strange.
No matter which plotting command I use, the problem can be reproduced with just the 'plot' command, for instance.

Accepted Answer

FX
FX on 13 Aug 2016
I got the question answered succesfully at Stackoverflow. Here is the url: http://stackoverflow.com/questions/38890375/updating-chart-in-a-gui-with-timer-creates-a-new-figure-axes

More Answers (1)

Adam
Adam on 12 Aug 2016
'candle' looks like a very old function and does not seem to have a version that allows you to plot on a specified axes, but plot certainly does so e.g.
plot( hAxes, xData, yData )
is what you should always use rather than
axes( hAxes )
plot( xData, yData );
  1 Comment
FX
FX on 13 Aug 2016
Edited: FX on 13 Aug 2016
Well this works partially with plot, thank you. But still a new figure is popping up even that the data is going to the right figure. When I close that figure manually it pops up again during the next timer execution.
Also, how about the function highlow which can return a handle but does not take one as an input argument, can I somehow use the handle it returns to draw on the axes on the GUI?
Maybe I should give some feedback to Matlab about the candle function that it should take axes as an input.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!