绘图注释未显示在正确的位置
Plotly annotation not showing up at correct location
我有一个基本上是日期的x轴的时间线,以及特定日期事件的注释。它们的间隔不均匀,因为我想显示特定日期的事件。我已经指定了其中一个日期作为注释的x位置,但它没有显示在正确的位置。这是一把小提琴:https://jsfiddle.net/abalter/98phb124/
HTML:
<div id="myDiv" style="width: 600px; height: 300px;"></div>
<div id="hoverinfo" style="margin-left:80px;"></div>
Javascript:
var myPlot = document.getElementById('myDiv');
var hoverinfo = document.getElementById('hoverinfo');
var CA199 =
{
x: ["7/1/2015","7/13/2015", "8/1/2015", "9/1/2015", "9/11/2015","10/1/2015"],
y: ["", "", "", "", "", ""],
type: 'linear',
mode: 'markers'
};
var data = [CA199];
var layout =
{
title: "Title",
height: 0,
xaxis:
{
tickfont:
{
color:"rgb(107, 107, 107)",
size:11
},
ticks:"outside",
tickwidth:1,
tickangle:40,
ticklen:5,
showticklabels:true,
showline:true,
type:"scatter",
autorange:true,
tickmode:"auto",
showgrid: false
},
yaxis:
{
autorange: true,
showgrid: false,
zeroline: false,
autotick: false,
ticks: '',
showticklabels: false,
showline: false,
},
annotations:
[
{
x: "09/11/2015",
y: 0,
align: "center",
arrowcolor: "rgba(255, 0, 255, 0.53)",
arrowhead: 5,
arrowsize: 1,
ax: -0,
ay: -50,
bgcolor: "rgba(255, 0, 255, 0.29)",
bordercolor: "rgba(0, 0, 0, 0)",
borderpad: 3,
borderwidth: 0,
font: {size: 14},
text: "CA12-3: 144",
textangle: 0
}
]
};
Plotly.plot
(
'myDiv',
data,
layout,
{scrollZoom: true}
);
myPlot
.on('plotly_hover', function(data)
{
var infotext = data.points.map(function(d)
{
return (d.data.name+': x= '+d.x+', y= '+d.y.toPrecision(3));
});
hoverinfo.innerHTML = infotext.join('');
})
.on('plotly_unhover', function(data)
{
hoverinfo.innerHTML = '';
});
community.plot.ly的etienne轻而易举地得到了公认的答案。https://community.plot.ly/t/fine-tuning-annotation-position/760
设置一个假yaxis范围应该可以做到这一点。
https://jsfiddle.net/etpinard/98phb124/7/43
yaxis:
{
range: [0, 1],
showgrid: false,
zeroline: false,
autotick: false,
ticks: '',
showticklabels: false,
showline: false,
},
相关文章:
- jquery试图按名称获取按钮位置
- 我可以获得相对于被点击元素的确切点击位置吗
- 谷歌地图固定位置覆盖
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 循环比赛位置算法
- es6 相当于下划线查找位置
- jQuery循环在特定位置暂停
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- 自定义函数中的光标位置
- 安卓平台上的QWebView HTML5地理位置
- DIV并排,位置不正确
- 使用jQuery更改元素的顶部位置
- 在谷歌地图上绘制位置数据库
- 跟踪jqplot垂直折线图的鼠标位置
- 设置画布渲染器的x和y位置
- 固定位置菜单时滚动,直到它击中一个相对容器的底部
- 绘图注释未显示在正确的位置
- 使用地理位置数据限制websocket注释可见性
- 基于y轴位置对浮动图进行注释
- Regex javascript,从某个位置匹配并跳过包含注释块的行