<i id='seaxf'><tr id='seaxf'><dt id='seaxf'><q id='seaxf'><span id='seaxf'><b id='seaxf'><form id='seaxf'><ins id='seaxf'></ins><ul id='seaxf'></ul><sub id='seaxf'></sub></form><legend id='seaxf'></legend><bdo id='seaxf'><pre id='seaxf'><center id='seaxf'></center></pre></bdo></b><th id='seaxf'></th></span></q></dt></tr></i><div id='seaxf'><tfoot id='seaxf'></tfoot><dl id='seaxf'><fieldset id='seaxf'></fieldset></dl></div>

    <small id='seaxf'></small><noframes id='seaxf'>

  1. <tfoot id='seaxf'></tfoot>
        <bdo id='seaxf'></bdo><ul id='seaxf'></ul>
      <legend id='seaxf'><style id='seaxf'><dir id='seaxf'><q id='seaxf'></q></dir></style></legend>
    1. 在调整窗口大小之前,ChartJS 不会在引导选项卡内绘制图形

      ChartJS won#39;t draw graph inside bootstrap tab until window resize(在调整窗口大小之前,ChartJS 不会在引导选项卡内绘制图形)

      <legend id='1Q0pc'><style id='1Q0pc'><dir id='1Q0pc'><q id='1Q0pc'></q></dir></style></legend>
        <tbody id='1Q0pc'></tbody>

          <bdo id='1Q0pc'></bdo><ul id='1Q0pc'></ul>
        • <tfoot id='1Q0pc'></tfoot>
          <i id='1Q0pc'><tr id='1Q0pc'><dt id='1Q0pc'><q id='1Q0pc'><span id='1Q0pc'><b id='1Q0pc'><form id='1Q0pc'><ins id='1Q0pc'></ins><ul id='1Q0pc'></ul><sub id='1Q0pc'></sub></form><legend id='1Q0pc'></legend><bdo id='1Q0pc'><pre id='1Q0pc'><center id='1Q0pc'></center></pre></bdo></b><th id='1Q0pc'></th></span></q></dt></tr></i><div id='1Q0pc'><tfoot id='1Q0pc'></tfoot><dl id='1Q0pc'><fieldset id='1Q0pc'></fieldset></dl></div>

            <small id='1Q0pc'></small><noframes id='1Q0pc'>

              1. 本文介绍了在调整窗口大小之前,ChartJS 不会在引导选项卡内绘制图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 bootstrap 的选项卡,每个选项卡内都有 chartjs 图表.

                I'm using bootstrap's tabs with chartjs charts inside every tab.

                发生的一个问题是图形画布不会在我调整浏览器窗口大小之前被绘制.最新的 Chrome 和 Firefox 都在发生这种情况.

                One problem that have occurred though is that the graph canvas wont be drawn until i resize the browser window. And this is happening in both latest Chrome and Firefox.

                我一直在尝试不同的解决方案,例如在更改选项卡后绘制图表但没有结果.

                I've been trying different solutions as drawing the graph after the tab is changed but with no results.

                不幸的是,我无法在 jsfiddle 中复制问题,不知何故它似乎在那里工作.但是除了 html5 样板之外,还有几乎所有的代码.

                Unfortunately I was unable to duplicate the problem in jsfiddle, somehow it seems to work there. But there's pretty much all the code, besides the html5 boilerplate.

                有谁知道为什么会发生这种行为?谢谢!

                Does anyone know possibly why this behavior happens? Thanks!

                /**
                 * ChartJS using JSON data and moment.js for time display
                 * Code is quite ugly due to experimentation
                 */
                
                function getJSON(){
                
                    $.getJSON( "data.json", function(data){
                        var dataArray = [];
                        console.log(data);
                        var series = {};
                
                        for (var x in data.Series) {
                            var dates = [];
                            var values = [];
                            // Loop across all the measurements for every serie.
                            for (var i = 0; i < data.Series[x].length; i++) {
                                var obj = data.Series[x][i];
                                dates.push(moment(obj.Date).format("MMMM Mo"));
                                values.push(obj.Value);
                            }
                            // Keep the list of dates and values by serie name.
                            series[x] = {
                                dates: dates,
                                values: values
                            };
                        }
                    //some debug stuff
                    console.log(series.height.dates);
                    console.log(series.height.values);
                
                    var dataArray = {
                        labels: series.height.dates,
                        datasets: [
                        {
                            label: "Height",
                
                            strokeColor: "rgb(26, 188, 156)",
                            pointColor: "rgba(220,220,220,1)",
                            pointStrokeColor: "#fff",
                            pointHighlightFill: "#fff",
                            pointHighlightStroke: "rgba(220,220,220,1)",
                            data: series.height.values
                        }
                        ]
                    };
                
                    function chartFunc(dataArray) {
                
                        var ctx = document.getElementById("heightChart").getContext("2d");
                        var myLineChart = new Chart(ctx).Line(dataArray, { 
                            scaleShowGridLines : true, 
                            bezierCurve : true, 
                            bezierCurveTension : 0.4, 
                            datasetStroke : false, 
                            fillColor: "rgba(0,0,0,0)", 
                            datasetFill : false,
                            responsive: true,
                            showTooltips: true,
                            animation: false,
                        }); 
                    } //chartFunc
                
                    chartFunc(dataArray);
                
                    }); //JQ getJSON
                
                }//getJSON
                
                
                $( document ).ready(function() {
                
                    getJSON();
                
                    $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
                        console.log("TAB CHANGED");
                    });
                
                });
                

                http://jsfiddle.net/woqsazau/1/

                推荐答案

                在我的例子中,我在引导 modal 内的引导选项卡中使用 ChartJs.我的问题是模式,而不是选项卡.与Chartjs相关的代码必须设置成

                In my case I was using ChartJs inside a bootstrap tab inside a bootstrap modal. The problem in my case was the modal, and not the tab. The code related with Chartjs has to be set into

                $('#modal').on('shown.bs.modal', function (event) {
                  $.getJSON(http://whatever.com/file.js, function( data ) {
                    var ctx = document.getElementById("heightChart").getContext("2d");
                    window.myNewChart = new Chart(ctx).StackedBar(data,  {
                      responsive : true,
                      animation: true,
                      showScale: true,
                      multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>"
                    });
                
                  });
                });
                

                我在其他问题上找到了提示:Bootstrap Modal with Chart.js linechart

                I have found a hint on this other issue: Bootstrap Modal with Chart.js linechart

                这篇关于在调整窗口大小之前,ChartJS 不会在引导选项卡内绘制图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
              2. <legend id='ZENBy'><style id='ZENBy'><dir id='ZENBy'><q id='ZENBy'></q></dir></style></legend>

                <i id='ZENBy'><tr id='ZENBy'><dt id='ZENBy'><q id='ZENBy'><span id='ZENBy'><b id='ZENBy'><form id='ZENBy'><ins id='ZENBy'></ins><ul id='ZENBy'></ul><sub id='ZENBy'></sub></form><legend id='ZENBy'></legend><bdo id='ZENBy'><pre id='ZENBy'><center id='ZENBy'></center></pre></bdo></b><th id='ZENBy'></th></span></q></dt></tr></i><div id='ZENBy'><tfoot id='ZENBy'></tfoot><dl id='ZENBy'><fieldset id='ZENBy'></fieldset></dl></div>

              3. <small id='ZENBy'></small><noframes id='ZENBy'>

                  <tbody id='ZENBy'></tbody>
                  <tfoot id='ZENBy'></tfoot>

                        <bdo id='ZENBy'></bdo><ul id='ZENBy'></ul>