浮点双轴 [英] Double axes in flot
问题描述
我想使用flot创建一个包含四个象限的图形.我需要在图表的左侧和右侧都有标签-带有相同的刻度.这是我的代码:
I want to create a graph with four quadrants using flot. I need to have labels on both the left and right-hand sides of the graph - with the same ticks. Here is my code:
$.plot($("#placeholder"), [ [<%=points%>] ], { series: {lines: { show: false },
points: { show: true }},
yaxes: [{ ticks:[[0,"Left"]],max: 100, min:-100 },
{ position: "Right",ticks:[[0,"Right"]], max:100, min: -100 }],
xaxis: { ticks:[[0,"Bottom"]], max: 100, min:-100 } });
我得到了左"和下"标签,但右侧没有任何标签.预先感谢您提供的任何帮助.
I get the "Left" and "Bottom" labels but nothing on the right-hand side. Thanks in advance for any help you can provide.
推荐答案
我遇到了同样的问题.为了使次要y轴显示在图的右侧,您需要将其连接到一个序列,但这在显示的数据范围之外:
I had this same issue. In order to have the secondary y-axis appear on the right side of the plot, you need to have a series connected to it, but that lies outside your displayed data range:
{label:"dummy data",data:[[-1000,-100],[-1000,100]], yaxis:2} //yaxis array is indexed from 1
由于您的范围似乎是固定的,因此与刻度线匹配非常简单.我的范围和价格变动是高度动态的,因此我通过将完整的重复系列主数据连接到次要yaxis来使价格变动得以匹配.我只是在x轴上移动了它,使其完全超出了显示范围.
Since your range appears to be fixed, matching the ticks is pretty straighforward. My range and ticks was highly dynamic, so I got the ticks to match by including a complete duplicate series of my primary data hooked to the secondary yaxis. I just shifted it on the xaxis to be completely out of range for display.
是的,这很浪费,因为它涉及传递额外的数据.但是,直到Flot支持显示不带圆锥的yaxes为止,这才可以完成.
Yes, this is wasteful, since it involves delivering extra data. But until Flot supports showing yaxes without series conencted, this will get it done.
这篇关于浮点双轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!