Microsoft Chart Will Not Resize with Bootstrap

I was having trouble resizing the Microsoft chart that comes with asp.net.  I am using Bootstrap but oddly enough it will only resize the width of the chart image not the height.  When you look at the page source the image is rendering with inline style width and height.  To have the bootstrap img-responsive class work properly, the width and height of the image should not be set according to the posts I was reading.  Not setting the height and width of the image did not work, it would default to 300x300, so I resorted to a Jquery solution which removes the styles from the element when the page is ready.

Note: I was able to have the chart in a Bootstrap grid without the img-responsive and it would auto resize the image once the inline styles on it were removed.  Neat.

<script>
 $(function () {
        $("#<%= Chart1.ClientID %>").attr('style', '');
    });
</script>
 ....


   <asp:Chart ID="Chart1" runat="server" CssClass="img-responsive" ClientIDMode="Static"
                                IsMapAreaAttributesEncoded="True">
                                <Series>
                                    <asp:Series ChartArea="myChartArea" Name="Series1" ChartType="Doughnut"
                                        XValueMember="xVALNAME" YValueMembers="yVALNAME"
                                        XValueType="String" YValueType="Double">
                                    </asp:Series>

                                </Series>
                                <ChartAreas>
                                    <asp:ChartArea Name="myChartArea" Area3DStyle-Enable3D="true">
                                        <AxisY Title="xVALNAME"></AxisY>
                                        <AxisX Title="yVALNAME"></AxisX>
                                        <Area3DStyle Enable3D="True" Inclination="20" />
                                    </asp:ChartArea>
                                </ChartAreas>
                            </asp:Chart>

-----

ref
http://stackoverflow.com/questions/1229688/how-can-i-erase-all-inline-styles-with-javascript-and-leave-only-the-styles-spec
http://www.codeproject.com/Tips/361447/Working-with-MS-Chart

Comments

Popular posts from this blog

Asp.net Publishing Broke Site - "App_WebReferences is not allowed because the application is precompiled"

Telerik - Custom Group Footers In RadGrid

Bootstrap Modal Popup is Grayed Out