Google 可视化在 AJAX Control Toolkit Tab Control 中很小

发布于 2024-08-23 08:11:45 字数 2896 浏览 5 评论 0原文

我正在尝试在 asp.net AJAX Toolkit 选项卡控件内使用 google 可视化(柱形图),但我遇到了小(字面意思)问题。

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

下面是 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>

I'm trying to use a google visualisation, the column chart, inside an asp.net AJAX Toolkit Tab Control, but I'm having small (literally) problems.

If I add the visualisation to the tab that's displayed by default when the page loads, the bar chart displays correctly, however, if I add the same control to another tab and reload the page, when I click on the other tab, the control is displayed, but its tiny and unusable.

Here's some code for a test.aspx page that illustrates the problem:

<%@ 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£冰雨忧蓝° 2024-08-30 08:11:45

好吧,我没有得到对这篇文章的任何回复,所以这就是我解决这个问题的方法,希望它对某人有所帮助。

我从未真正找到这个问题的根源,但我发现如果我延迟可视化的加载,直到单击包含它的选项卡,那么问题就会消失。

在 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 函数,如果当前活动选项卡是一个,则在页面加载时执行该函数包含可视化,然后我加载它。

Ok, I didn't get a single response to this post so here is how I worked around the problem, hope it helps someone.

I never actually got the the root of this problem but I found that if I delayed the loading of the Visualisations till the tab that contains it is clicked then the problem goes away.

In the TabControl I call a JavaScript function to load the tabs visualisation when clicked:

<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>

The JavaScript function

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
            }
        }

 }

During postback the active tab could change, to cope with this I have a JavaScript function that executes when the page loads, if the current active tab is one containing a visualisation then I load it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文