简体   繁体   English

浮点图迁移图例

[英]relocating legend of flot plot

I'm using flot as a plotting javascript utility. 我正在将flot用作绘图javascript实用程序。 Here is the sample I'm using which allows toggle... https://github.com/flot/flot/blob/master/examples/series-toggle/index.html 这是我正在使用的允许切换的示例... https://github.com/flot/flot/blob/master/examples/series-toggle/index.html

What I want to achieve is to move the legend to the right side of the plot as having several curves causes the legend to grow big and block the view. 我想要实现的是将图例移至图的右侧,因为具有多个曲线会导致图例变大并阻塞视图。 I tried the "aboveData" option as the api suggested: 我尝试了api建议的“ aboveData”选项:

$.plot("#placeholder", data, {
                    yaxis: {
                        min: 0
                    },
                    xaxis: {
                        tickDecimals: 0
                    },grid: {show:true, aboveData:false},
                });

It did not do anything. 它什么也没做。 Then I tried changing the css to add a "left" property to the table: 然后,我尝试更改CSS以向表添加“ left”属性:

.legend table {
    border-spacing: 5px;
    left:800px;
}

which does move the legend table to right but there is an opaque white div container left behind. 它确实将图例表向右移动,但是后面有一个不透明的白色div容器。 Any idea how to remove it? 知道如何删除它吗?

You method kinda works if you use the parent legend div instead of the table: 如果您使用父legend div而不是表格,则方法有点奏效:

.legend {
    position: absolute;
    left:800px;
}

This is probably not the best way to achieve your goals though. 不过,这可能不是实现目标的最佳方法。 flot provides the ability to relocate the legend to a container (div) of your choice. flot 可以将图例重定位到您选择的容器(div)。 So to put the legend right of the plot, I'd do: 因此,为了使图例正确,我将执行以下操作:

<div id="flotGraph" style="width: 400px; height: 400px; float: left"></div>
<div id="legendContainer" style="float: left"></div>

And then use the legend container property: 然后使用图例容器属性:

    $.plot("#placeholder", data, {
        yaxis: {
            min: 0
        },
        xaxis: {
            tickDecimals: 0
        },
        legend: {
            container: $('#legendContainer')
         }
      });

Here's an example . 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM