Double axes in flot

帅比萌擦擦* 提交于 2019-12-08 04:21:56

问题


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.


回答1:


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

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.

Yes, this is wasteful, since it involves delivering extra data. But until Flot supports showing yaxes without series conencted, this will get it done.



来源:https://stackoverflow.com/questions/10465636/double-axes-in-flot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!