绘图创建一条垂直线以显示平均值 [英] plotly create a vertical line to show average
问题描述
所以我正在尝试创建一个水平条形图,其中有一条显示平均值的水平线.
So i am attempting create a horizontal bar chart that has a horizontal line showing average.
到目前为止,我尝试了以下操作:
So far i have attempted the following:
首先添加我的 barChart 系列(它来自以下数组):
First added my barChart series (it comes from the following array):
"series": [
{
"value": 100, "label": "F1"
},
{
"value": 25, "label": "F2"
},
{
"value": 30, "label": "Jedi Jeremiah 555"
},
{
"value": 40, "label": "F4"
},
{
"value": 55, "label": "F5"
},
{
"value": 60, "label": "F6"
},
{
"value": 71, "label": "F7"
},
{
"value": 15, "label": "F8"
},
{
"value": 88, "label": "F9"
},
{
"value": 90, "label": "F10"
}
]
转换为以下对象的数组:
Which converts to an array of the following objects:
{name: 'F1', orientation: "h", x: [100], y: ["F1"]}
然后我添加以下系列:
{
name: 'average organization',
type: 'scatter',
x: [60],
orientation: 'h'
}
这将创建以下图表:
如您所见,只有一个蓝点表示平均值,这不是我要查找的结果.
As you can see there is only a blue dot indicating the average which is not the result im looking for.
我知道有一些形状,但我希望将其作为图表的一部分,以便您可以选择或取消选择它.
I know that there are shapes however i wish to have it as a part of the chart so that you can either select or deselect it.
有谁知道你是如何做到这一点的?
Does anyone know how you might achieve this?
推荐答案
如果您提供一个 jsFiddle 或 codePen 或其他示例来直接执行它会有所帮助:-)我认为问题是,您想要一条垂直线,但将 orientation: 'h'
设置为最后一个average-organisation"-object 而不是使用 orientation: 'v'代码>.
It would help if you would provide a jsFiddle or codePen or other example to execute it directly:-)
I think the problem is, that you want to have a vertical line but set orientation: 'h'
to the last "average-organisation"-object instead using orientation: 'v'
.
我在 jsFiddle 中复制了您的示例并添加了所需的行为:https://jsfiddle.net/vepycde0/
I reproduced your example in a jsFiddle and add the desired behaviour: https://jsfiddle.net/vepycde0/
希望有帮助:-)
编辑:要隐藏 yAxis 上的0",请使用 y: [""]
,如该 jsFiddle 所示:https://jsfiddle.net/vepycde0/1/
Edit: For hiding the "0" on yAxis use y: [""]
as seen in that jsFiddle: https://jsfiddle.net/vepycde0/1/
这篇关于绘图创建一条垂直线以显示平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!