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