Update bar chart UIAxes from EditField value without deleting older plot
Afficher commentaires plus anciens
Hi. I am building an app where whenever I enter value in EditField it automatically plot a bar chart in UIAxes.
I manage to do that. However, I would like to continously update the bar chart wehenever new value enter into the EditField without deleting the older plot (bar chart).
Appreciate your help on this matter.
14 commentaires
Cris LaPierre
le 10 Mai 2023
Does it add a new bar to the chart every time the user enters another number in the edit field? Does it just adjust the height of a single bar?
FEH
le 10 Mai 2023
Cris LaPierre
le 10 Mai 2023
Modifié(e) : Cris LaPierre
le 10 Mai 2023
So the first time adds the purple bars, and the second time adds the maroon ones?
Is the image from your app? If so, that was created using bar3, but the sample code you shared uses bar. It would be helpful if you could share your actual code.
FEH
le 10 Mai 2023
Cris LaPierre
le 10 Mai 2023
Modifié(e) : Cris LaPierre
le 10 Mai 2023
MATLAB automatically adjusts the width of the bars as the number of bars increases. Does that matter? Do you know how many bars will be in each group a priori?
FEH
le 10 Mai 2023
Walter Roberson
le 10 Mai 2023
Use hold on ? Or on App Designer
hold(app.HANDLE_OF_AXES, 'on')
FEH
le 10 Mai 2023
I suggest you test again.
ax = gca; %but use app.HANDLE_OF_AXES in your real code
bar(ax, 1, 5)
hold(ax, 'on')
bar(ax, 2, 3)
bar(ax, 3, -1)
bar(ax, 4, 2)
hold(ax, 'off')
Simon Chan
le 10 Mai 2023
What is the content you entered in EditField? And could you show the callback of the CALCULATE button?
FEH
le 10 Mai 2023
Simon Chan
le 10 Mai 2023
Modifié(e) : Simon Chan
le 10 Mai 2023
The following may be a workaround for you, noticed that someone may have a better solution.
When you define the UIAxes, set its user data to an empty array
set(app.UIAxes,'UserData',[]);
When you enter a new EditField, the UserData will be updated.
In this case, it simply overwrite the previous plot with a new plot and hence no need to use hold on and hold off.
However, if you use the same axis for a completely new plot, you need to set the UserData of the UIAxes to [] somewhere otherwise the old data will not be clear.
Y = [app.TotalAllowableWeighttonEditField.Value;app.ActualTotalWeighttonEditField.Value];
app.UIAxes.UserData = [app.UIAxes.UserData;Y'];
bar(app.UIAxes,X, app.UIAxes.UserData,'grouped','FaceColor','flat');
FEH
le 10 Mai 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



