Adding clickable hyperlink to data tip label or plot point
조회 수: 22 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Voss
2023년 8월 29일
"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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
