jquery - Flot 饼图中左侧的偏移量不起作用

标签 jquery jquery-plugins charts flot pie-chart

我想将饼图放置在图表的左上角,但left属性不是 工作正常,另一方面 top 工作正常。

My code - Jsfiddle

代码:

$(function () {
     var data = [
    { label: "Read", data: 50, color: '#614E43' },
    { label: "Unread", data: 150, color: '#F5912D' }];
      $.plot($("#star"), data, 
      {
        series: {

          pie: {        
            radius: 0.2,  
            innerRadius: 0.125,
            show: true,
            stroke: {
                width: 0.1,
                color: '#808080'
            },
            offset: {
                  top: -70,
                  left: -30
            }
          }
        }
      });
});

最佳答案

问题出在 setupPie() 函数上。我相信这是一个错误。

饼图不允许左侧位置低于最大半径,即使实际半径更小。

http://flot.googlecode.com/svn/trunk/jquery.flot.pie.js @ 第 204 行

if (centerLeft<maxRadius)
    centerLeft = maxRadius;
else if (centerLeft>canvas.width-maxRadius)
    centerLeft = canvas.width-maxRadius;

如果您设置了相对半径,则不应根据最大宽度检查左侧。

相反,应该是这样的:

//calculate the radius the same way drawPie() does
var radius = options.series.pie.radius;
if (options.series.pie.radius < 1)
    radius *= maxRadius;

//and compare to that value
if (centerLeft < radius)
    centerLeft = radius;
else if (centerLeft > canvas.width-radius)
    centerLeft = canvas.width-radius;

编辑:

我已经 fork 了存储库并尝试了我的代码,似乎正在完成工作。

我的JSFiddle .

关于jquery - Flot 饼图中左侧的偏移量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18805888/

相关文章:

charts - 页面加载时谷歌图表上始终可见的工具提示?

javascript - D3 : looping transition with dynamic name

javascript - jquery 不适用于具有特定网页的 WebBrowser 控件

javascript - 本地 anchor 链接在 chrome 桌面浏览器中不起作用

带有轮播的 jQuery Cycle2 插件无法工作;控制台中没有错误

jquery 选项卡在顶部添加空间

jquery - 在一个页面上实现多个 jQuery 插件

javascript - 如何对 TableView 中的列值求和并将其显示在 Google Charts 的标签中?

charts - 如何向 c3.js 图表添加标题

javascript - 我们如何在不同选项卡上序列化 selectpicker 插件文本?