简体   繁体   English

在JavaScript中更改图表的高度和宽度属性

[英]Change chart height and width property in javascript

I have this button that when is clicked it's supposed to downsize a chart but it's not working. 我有这个按钮,当单击它时应该缩小图表的大小,但是它不起作用。 I don't want to change the style height and width attribute since this makes the chart look stretched. 我不想更改样式的height和width属性,因为这会使图表看起来很拉伸。 That's why I'm trying to change the property that's in the chart element. 这就是为什么我要更改图表元素中的属性的原因。

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

When the button is clicked it seems the chart is reloaded but its the same size as before. 单击该按钮时,似乎重新加载了图表,但其大小与以前相同。 I also added a document.write("Hello") to make sure the button is activating the function and it works so it seems is something wrong with the graph or the script. 我还添加了一个document.write(“ Hello”),以确保该按钮正在激活该功能并且可以正常工作,因此图形或脚本似乎有问题。

Why is the code not working? 为什么代码不起作用?

The Hieght and Width are asp control properties. Hieght和Width是asp控件属性。

Try to change the css attributes of the chart: 尝试更改图表的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