Effacer les filtres
Effacer les filtres

change datatip for segments of stacked bar charts

11 vues (au cours des 30 derniers jours)
endystrike le 25 Juin 2020
Hi everyone! ;)
I'm struggling in trying to change data tips for segments of a stacked bar chart (and of course I'd like to change the format and label also for X data of the data tip itself).
From the following codes, I'd like to:
  • change the Y segment label to the corresponding name of the ticker from "all_i(idx)" (of course I'd do it for each element of included in "idx" vector)
  • change the format value of Y segment to '%.2f%%'
  • to change the label "X" to "Date"
  • change the format of the corresponding date as 'dd/MM/yyyy'
Two important notes:
  • "date_ax" is a datetime vector
  • "all_i" is a string vector
  • "idx" is a numeric vector
I'm sorry but reading the data tip help I could do everything on other types of charts, but I'm facing issues with stacked bar charts... :(
Thanks a lot for your precious help! :)
alloc_f = figure('units','normalized','position',[0 0 1 1]); %#ok<NASGU>
ax = bar(date_ax,100*stocks_glob_perc(1:end-1,idx),'stacked','BarWidth',1,'FaceColor','flat');
newColors = maxdistcolor(length(idx),@srgb_to_Jab,'sort','hue',...
'exc',[0,0,0; 1,1,1; 0.59,0.54,0.54; 0.30,0.24,0]);
for k=1:length(idx)
ax(k).CData = newColors(k,:);
xlim([date_ax(FirstDayOfPtot)-5 date_ax(end)+5]);
ylim([0 100]);

Réponse acceptée

Seth Furman
Seth Furman le 28 Oct 2020
Take a look at the documentation for creating custom data tips.
x = datetime('2020-01-01'):days(1):datetime('2020-01-03');
x.Format = 'dd/MM/uuuu';
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
b = bar(x,y,'stacked','BarWidth',1,'FaceColor','flat','LineStyle','none');
templates = [b.DataTipTemplate];
names = ["Name1","Name2","Name3","Name4"];
for i = 1:length(templates)
template = templates(i);
template.DataTipRows(1).Label = 'Date:';
template.DataTipRows(3).Label = names(i)+":";
template.DataTipRows(3).Format = '%.2f%%';

Plus de réponses (0)




Community Treasure Hunt

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

Start Hunting!

Translated by