简体   繁体   English

AngularJS ui-chart在ui-bootstrap选项卡中不起作用

[英]AngularJS ui-chart not working in ui-bootstrap tabs

I use ui-chart angularjs module to show a line graph, the thing is when I put it in ui-bootstrap tabs, it only show the line graph at the first tab, it wouldn't show at the second or third tab. 我使用ui-chart angularjs模块显示折线图,问题是当我将其放在ui-bootstrap选项卡中时,它仅在第一个选项卡中显示折线图,而不会在第二个或第三个选项卡中显示。

When I read the jqPlot documentation (ui-chart is a directive for jqPlot), it says it needs to use replot(), but I don't know how to implement this in ui-chart. 当我阅读jqPlot文档 (ui-chart是jqPlot的指令)时,它说它需要使用replot(),但是我不知道如何在ui-chart中实现它。

Can anyone give me a heads up on this? 有人可以给我提个醒吗?

Did you include all the plugins required ? 您是否包括了所需的所有插件? You need to include the adequate plugin for each graph. 您需要为每个图包括适当的插件。 I forgot it a lot of times. 我很多次忘记了。 Otherwise, I think we might need the code to do more investigation. 否则,我认为我们可能需要代码进行更多调查。 for example to draw a pie you have to include : 例如画一个饼,您必须包括:

<script src=".../jqplot/plugins/jqplot.pieRenderer.js" type="text/javascript"></script>

in addition. 此外。

I've managed to accomplish that by modifying the ui-chart directive, adding the following to the end of it: 通过修改ui-chart指令,并在其末尾添加以下内容,我设法实现了这一点:

var plot = $.jqplot(elem.attr('id'), data, opts);

// search for a tabpanel (jquery-ui tabs) containing the chart
elem.closest('.tabpanel').bind('tabsactivate',
    function(event, ui) {
        if (plot._drawCount === 0) {
            plot.replot();
        }
});

The if _drawCount part is very important because reploting a chart is a heavy-weight operation. if _drawCount部分非常重要,因为重新部署图表是一项繁重的操作。

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

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