我想将饼图
放置在图表
的左上角,但left
属性不是
工作正常,另一方面 top
工作正常。
代码:
$(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/