Google可视化在AJAX Control Toolkit选项卡控件中很小

时间:2010-02-25 19:28:35

标签: tabs controls ajaxcontroltoolkit tabcontrol google-visualization

我正在尝试使用谷歌可视化,柱形图,在asp.net AJAX工具包标签控件中,但我有小(字面上)问题。

如果我将可视化添加到页面加载时默认显示的选项卡,则条形图会正确显示,但是,如果我将同一控件添加到另一个选项卡并重新加载页面,当我单击其他选项卡时,显示控件,但很小且无法使用

以下是test.aspx页面的一些代码,用于说明问题:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="TestProject._Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>

    <script type="text/javascript">
        google.load('visualization', '1', { packages: ['columnchart'] });
    </script>

    <script type="text/javascript">
        function drawVisualization() {
            // Create and populate the data table.
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Name');
            data.addColumn('number', 'Height');
            data.addRows(3);
            data.setCell(0, 0, 'Tong Ning mu');
            data.setCell(1, 0, 'Huang Ang fa');
            data.setCell(2, 0, 'Teng nu');
            data.setCell(0, 1, 174);
            data.setCell(1, 1, 523);
            data.setCell(2, 1, 86);

            // Create and draw the visualizations.
            new google.visualization.ColumnChart(document.getElementById('visualization1')).
            draw(data, null);
            new google.visualization.ColumnChart(document.getElementById('visualization2')).
            draw(data, null);
        }
        google.setOnLoadCallback(drawVisualization);
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <cc1:TabContainer ID="TabContainer1" runat="server">
            <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
                <ContentTemplate>
                    <div id="visualization1" style="width: 300px; height: 300px;">
                    </div>
                </ContentTemplate>
            </cc1:TabPanel>
            <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel2">
                <ContentTemplate>
                    <div id="visualization2" style="width: 300px; height: 300px;">
                    </div>
                </ContentTemplate>
            </cc1:TabPanel>
        </cc1:TabContainer>
    </div>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

好的,我没有收到这篇文章的回复,所以这就是我如何处理这个问题,希望它对某人有帮助。

我从来没有真正得到这个问题的根源,但我发现如果我延迟加载Visualisations直到包含它的标签被点击,那么问题就会消失。

在TabControl中,我调用JavaScript函数在单击时加载选项卡可视化:

<cc1:TabContainer ID="TabContainer1" runat="server" OnClientActiveTabChanged="tabChanged">
  <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
    <ContentTemplate>
      <div id="visualization1" style="width: 300px; height: 300px;"></div>
    </ContentTemplate>
  </cc1:TabPanel>
    <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel2">
      <ContentTemplate>
        <div id="visualization2" style="width: 300px; height: 300px;"></div>
      </ContentTemplate>
  </cc1:TabPanel>
</cc1:TabContainer>

JavaScript函数

function tabChanged(sender, args) {
        var ActiveTab = sender.get_activeTabIndex();
        if (sender.get_activeTabIndex() == 0) {
            if (tab0Loaded != true) { 
                //load the visualisation
                new google.visualization.ColumnChart(document.getElementById('visualization2')).draw(data, null);
                tab0Loaded = true
            }
        }
        if (sender.get_activeTabIndex() == 1) {
            if (tab1Loaded != true) { 
                //load the visualisation
                new google.visualization.ColumnChart(document.getElementById('visualization2')).draw(data, null);
                tab1Loaded = true
            }
        }

 }

在回发期间,活动标签可能会发生变化,为了解决这个问题,我有一个在页面加载时执行的JavaScript函数,如果当前活动标签是包含可视化的标签,那么我加载它。