简体   繁体   English

在下拉菜单中时在div区域之外呈现的Google Pie图表

[英]Google Pie chart rendered outside of div area when inside a dropdown

I have an issue with my pie chart being rendered outside of its parent div when located into a dropdown. 我的饼形图位于下拉列表中时,在其父div之外呈现了一个问题。

The chart loads after the page is ready so if I actually hover the dropdown and wait for the chart to load, it loads correcly. 图表在页面准备好后加载,因此,如果我实际上将鼠标悬停在下拉列表上并等待图表加载,则它会正确加载。 在此处输入图片说明

If I wait for the chart to load before I hover the dropdown, it does not load properly. 如果在悬停下拉列表之前等待图表加载,则无法正确加载。 在此处输入图片说明

Any idea to resolve this ? 有解决的办法吗? Thanks a lot ! 非常感谢 !

My view: 我的观点:

<div id="fmu_dropdown-profile" class="fmu_dropdown greybg menuright w250px">

        <div id="top_user_connected">
            <div id="user_connected_header" class="padding">
                <div class="bold padding-bottom">Profil rempli à {{ completeness }}%</div>

                <div id="chart_picture">

<div id="piechart" style="width: 220px; height: 180px"></div>


                    <a id="dropdown_picture" href="{{ path('fos_user_profile_edit') }}">
                            <img src="{{ profile_picture | imagine_filter('default')  }}" alt="Image de profil" class="img-responsive img-circle margin-auto">
                    </a>
                </div>

                <style rel="stylesheet">
                    #chart_picture {position: relative;}
                    #dropdown_picture {
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        margin-top: -60px;
                        margin-left: -60px;
                        z-index: 0;
                    }
                </style>

            </div>
            <div id="portfolio" class="padding whitefont">
                <p>Portfolio pris en compte :</p>
                {{ form(portfolio_form) }}
            </div>
        </div>


<script type="text/javascript">
    $(function(){
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['Nom',    'Valeur'],
                ["Profil rempli à ", {{ completeness }}],
                ['Manque', {{ 100 - completeness }}]
            ]);

            var options = {
                backgroundColor: { fill:'transparent'},
                pieSliceBorderColor : 'transparent',
                pieHole: 0.9,
                legend: 'none',
                pieSliceTextStyle :{fontsize : 16, color: 'transparent'},
                slices: {
                    0: { color: 'red'},
                    1: { color: '#444'}
                },
                chartArea : {width: '90%', height: '90%'}
            };

            var chart = new google.visualization.PieChart(document.getElementById('piechart'));

            chart.draw(data, options);
        }

        google.load('visualization', '1', {callback : function(){drawChart();}, 'packages':['corechart']})

    });

</script>

Drawing charts inside hidden divs breaks the dimension detection algorithms in the Visualization API. 隐藏的div内的绘图表破坏了Visualization API中的尺寸检测算法。 This is why when the div is exposed via hover everything works fine, but when it's hidden it all goes to hell. 这就是为什么当div通过hover一切正常,但是当它隐藏时一切都变为地狱。

The simplest solution is to explicitly set the chart height and width options to pixel values rather than percentages. 最简单的解决方案是将图表的高度和宽度选项显式设置为像素值,而不是百分比。

related: resizable-google-visualization-inside-jquery-accordion 相关: 可调整大小的谷歌可视化,内部jQuery手风琴

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

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