简体   繁体   English

Google Charts图表区域超出范围

[英]Google Charts chart area out of bounds

I have a Google Charts annotation chart like the one below inside some tabs. 我有一个Google Charts批注图,就像下面的一些标签所示。 The problem is, it's not being drawn properly as if it's a little out of bounds somehow. 问题是,它没有被正确地绘制,好像它有点超出范围。

I assume it's related to the chart being drawn when the page loads and then when I click on the tab, the size of the chart's container changes. 我假设它与页面加载时绘制的图表有关,然后单击选项卡时,图表容器的大小会发生变化。 But I'm not sure how to fix that. 但是我不确定该如何解决。 Any hint is greatly appreciated. 任何提示,不胜感激。

This is my chart: 这是我的图表:

google.load('visualization', '1', { 'packages': ['annotationchart'] });
google.setOnLoadCallback(drawChart);

function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('date', 'Date');
    data.addColumn('number', 'Kepler-22b mission');
    data.addColumn('string', 'Kepler title');
    data.addColumn('string', 'Kepler text');
    data.addColumn('number', 'Gliese 163 mission');
    data.addColumn('string', 'Gliese title');
    data.addColumn('string', 'Gliese text');
    data.addRows([
        [
            new Date(2314, 2, 15), 12400, undefined, undefined,
            10645, undefined, undefined
        ],
        [
            new Date(2314, 2, 16), 24045, 'Lalibertines', 'First encounter',
            12374, undefined, undefined
        ],
        [
            new Date(2314, 2, 17), 35022, 'Lalibertines', 'They are very tall',
            15766, 'Gallantors', 'First Encounter'
        ],
        [
            new Date(2314, 2, 18), 12284, 'Lalibertines', 'Attack on our crew!',
            34334, 'Gallantors', 'Statement of shared principles'
        ],
        [
            new Date(2314, 2, 19), 8476, 'Lalibertines', 'Heavy casualties',
            66467, 'Gallantors', 'Mysteries revealed'
        ],
        [
            new Date(2314, 2, 20), 0, 'Lalibertines', 'All crew lost',
            79463, 'Gallantors', 'Omniscience achieved'
        ]
    ]);

    var options = {
        displayAnnotations: true,
        'height': 500,
        'width': 900,
    };

    var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
    var chart2 = new google.visualization.AnnotationChart(document.getElementById('chart_div2'));
    var chart3 = new google.visualization.AnnotationChart(document.getElementById('chart_div3'));

    chart.draw(data, options);
    chart2.draw(data, options);
    chart3.draw(data, options);
}

And this is one of the tabs: 这是选项卡之一:

<ul class="nav nav-tabs" data-tabs="tabs">
@foreach (var item in Model)
{
    <li id="wellnav" class="@(item.Well == 1 ? "active" : "")"><a id="id2"
                                                                  href="#tab-@item.Well" 
                                                                  data-toggle="tab"">@item.Well</a></li>
}

<div id="tabs" class="tab-content">
    <div id="tab-1" class="tab-pane">
    <div id="chart_div"></div>       
</div>

UPDATE: 更新:

Here's an example on Fiddle on what I'm seeing. 这是关于我所看到的小提琴的一个例子。 Notice how the chart in tab 2 has broken dimensions or, at least, doesn't look right. 请注意,选项卡2中的图表尺寸已损坏,或者至少看起来不正确。 The fiddle is borrowed and modified from this post. 小提琴是借来的,并从修改这个职位。

http://jsfiddle.net/06rwpft8/1/ http://jsfiddle.net/06rwpft8/1/

It would seem the chart isn't rendered properly on hidden objects. 似乎图表未正确显示在隐藏的对象上。 Perhaps there are better ways to handle it directly in the google chart settings, but a solution would be to draw the actual chart when the tab is shown. 也许有更好的方法直接在Google图表设置中处理它,但是一种解决方案是在显示标签后绘制实际图表。 For example, call the draw once if the tab is clicked: 例如,如果单击选项卡,则调用一次抽奖:

$('a[title=content_2]').one('click',function(){
    chart2.draw(data, options);
});

Fiddle 小提琴

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

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