簡體   English   中英

在JavaScript中更改圖表的高度和寬度屬性

[英]Change chart height and width property in javascript

我有這個按鈕,當單擊它時應該縮小圖表的大小,但是它不起作用。 我不想更改樣式的height和width屬性,因為這會使圖表看起來很拉伸。 這就是為什么我要更改圖表元素中的屬性的原因。

 <script type="text/javascript">
        function downSize() {
            document.getElementById("chart1").Height = "350px";
            document.getElementById("chart1").Width = "600px";  
        }
    </script>

<!--Button-->
<asp:LinkButtonrunat="server" Text="DownSize" ID="DownSize" class="btn btn info" onClientClick="downSize()"></asp:LinkButton>

  <!--Graph-->
  <asp:Chart ID="chart1" runat="server"   EnableViewState="True" Height = "650px" Width = "1200px">
            <Legends>
                <asp:Legend Name="Legend">
                </asp:Legend>
            </Legends>
            <ChartAreas>
                <asp:ChartArea Name="DefaultChartArea" BorderColor="Gainsboro">
                    <AxisY >
                        <MajorGrid LineColor="LightSteelBlue" />
                        <MajorTickMark LineColor="Transparent" />
                    </AxisY>
                    <AxisX>
                        <MajorGrid LineColor="LightSteelBlue" />
                        <MajorTickMark LineColor="Transparent" />
                    </AxisX>
                </asp:ChartArea>
            </ChartAreas>
            <BorderSkin BackColor="Transparent" BorderColor="Transparent" BorderDashStyle="DashDot" SkinStyle="Emboss" />
</asp:Chart>

單擊該按鈕時,似乎重新加載了圖表,但其大小與以前相同。 我還添加了一個document.write(“ Hello”),以確保該按鈕正在激活該功能並且可以正常工作,因此圖形或腳本似乎有問題。

為什么代碼不起作用?

Hieght和Width是asp控件屬性。

嘗試更改圖表的css屬性:

 function downSize() {
            document.getElementById("chart1").style.height = "350px";
            document.getElementById("chart1").style.width = "600px";  
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM