Filter löschen
Filter löschen

Adding clickable hyperlink to data tip label or plot point

19 Ansichten (letzte 30 Tage)
Zak
Zak am 29 Aug. 2023
Bearbeitet: Zak am 29 Aug. 2023
I want to add a row to a plot data tip that is a hyperlink. Eventually I want it to go to a file on my computer, but for now I need to just figure out how to get the hyperlink into the data tip. I've created a simple script where I have a table with a sample number, three values, and a link. I can make a plot where I add the sample number as a row to the data tip information, but how can I add another row with a clickable hyperlink?
It doesn't necessarily need to be done through the data tip, but somehow I'd like to be able to click on a point and have it lead to a corresponding link.
% Sample data
sampleData = [
1, 0.1, 0.2, 0.3;
2, 0.5, 0.6, 0.7;
3, 0.8, 0.9, 1.0
];
links = repmat({'https://www.mathworks.com'},3,1);
% Create the table
sampleTable = table(...
sampleData(:, 1), ... % "sample" column
sampleData(:, 2), ... % "x" column
sampleData(:, 3), ... % "y" column
sampleData(:, 4), ... % "z" column
links);
figure
hold on
for i = 1:height(sampleTable) % using a loop since eventually I will color the points depending on the value of the "z" column
point = plot(sampleTable.Var2(i), sampleTable.Var3(i), '.','MarkerSize',20);
urow = dataTipTextRow("Sample",sampleTable.Var1(i));
point.DataTipTemplate.DataTipRows(end+1) = urow;
end
hold off

Akzeptierte Antwort

Voss
Voss am 29 Aug. 2023
"somehow I'd like to be able to click on a point and have it lead to a corresponding link"
You can do that with the line's ButtonDownFcn.
% Sample data
sampleData = [
1, 0.1, 0.2, 0.3;
2, 0.5, 0.6, 0.7;
3, 0.8, 0.9, 1.0
];
links = repmat({'https://www.mathworks.com'},3,1);
% Create the table
sampleTable = table(...
sampleData(:, 1), ... % "sample" column
sampleData(:, 2), ... % "x" column
sampleData(:, 3), ... % "y" column
sampleData(:, 4), ... % "z" column
links);
figure
hold on
for i = 1:height(sampleTable) % using a loop since eventually I will color the points depending on the value of the "z" column
point = plot(sampleTable.Var2(i), sampleTable.Var3(i), '.', ...
'MarkerSize',20,'ButtonDownFcn',@(~,~)web(sampleTable.links{i}));
end
hold off
  2 Kommentare
Zak
Zak am 29 Aug. 2023
Awesome!! Thanks so much. I replaced the web() function with winopen() to open a file and it does exactly what I was looking for if I put file paths in the links field!
'ButtonDownFcn',@(~,~)winopen(sampleTable.links{i})

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by