2013-08-02 74 views
3

为什么我的y轴放错了位置,我该如何修复它?我不明白为什么'y'轴位于图表的顶部。任何想法赞赏。将y轴标签放置在条形图上,JQuery

enter image description here

这些是我使用的选项。我尝试过抓住生成的y轴类,并手动使用css将其向左移动几个像素,但整个图形只是转移过来。据我所见,API中没有任何东西将y轴ticker标签相对于图形进行移动。

var options = { 
    colors: ["#99CCFF", "#000099", "#FF6C47"], 
    series: { 
    lines: {show: true, highlightColor:'#000099'}, 
    points: {show: true} 
    }, 
    xaxis: { 
    mode: "time", 
    timeformat: "%d/%m", 
    markings: [{color: "#000"}], 
    }, 
    yaxis: { 
    markings: [{color: "#000"}] 
    }, 
    grid: { 
    markings: [{color: "#fff"}], 
    labelMargin: 10, 
    axisMargin: 10, 
    backgroundColor: { 
     colors: [ "#000099", "#29A3CC" ] 
    }, 
    borderWidth: { 
     top: 1, 
     right: 1, 
     bottom: 2, 
     left: 2 
    } 
    }, 
    legend: { 
    show: true, 
    backgroundOpacity:.5, 
    labelBoxBorderColor: 1, 
    position: "nw", 
    margin: 5 
    } 
}; 
$.plot("#bpTable", [ 
    {label: "systolic", data: c1}, 
    {label: "diastolic", data: c2} 
], 
options); 
+0

图片让我们的人了解你的问题,但为了帮助你解决问题,你必须提供(部分)你的源代码并解释你试过的东西。 – DanFromGermany

+3

我想你是在隐藏的div内绘制图表('

')你是在手风琴或制表符中绘制图表或者当你调用'plot'时没有附加到'DOM'的东西? –

+2

查看http://stackoverflow.com/questions/5427725/flot-graph-does-not-render-when-parent-container-is-hidden,尤其是我最近对https://github.com/flot/flot发表的评论/ issues/1014 – DNS

回答

8

由于@captain建议,如果你在一个隐藏的占位符(bpTable)调用$.plot,那么这就是结果。直到您的占位符可见为止,请不要致电$.plot,或者使用一些技巧使其脱离屏幕(例如this example)。

+0

如果我们在两个内部使用制表符和手风琴和绘图图表,我们是否有某种黑客或诡计?罚款如果使用标签,但手风琴呢?我想这不是一个干净的解决方案,以延迟阴谋 –

+0

我通常会延迟'plot'调用,直到问题标签实际显示(使用标签的'activate'事件) – Ryley

2

由于@Ryley已经回答,您必须在显示选项卡后调用$ .plot。

当使用引导程序选项卡,你可以附加一个处理程序,并在它调用$ .plot:

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { 
    if ($(e.target).attr('href') == "#umsatz-tab") 
    { 
     $.plot("#chart", data, options); 
    } 
}); 

上引导标签的更多信息:http://getbootstrap.com/javascript/#tabs-usage(向下滚动到“活动”